home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User tools / VU Libraries / Controls.lib v3.0.15 & ref / Controls.lib < prev   
Encoding:
Text File  |  1993-09-17  |  131.3 KB  |  3,585 lines  |  [TEXT/MPS ]

  1.  
  2. #########################################################################
  3. #                            Controls.lib
  4. #========================================================================
  5. # Description:    This is a library of general Virtual User tasks.  All of the
  6. #                tasks do their own error checking and status/error reporting.
  7. #                Most of them return a 1 if the action was successful and a 0
  8. #                if the action could not be performed. GetNewFileName() returns
  9. #                a new file name, MatchApp(), the current application's name,
  10. #                and GetXYRandom, a random X,Y coordinate pair. Tasks that do
  11. #                not return a value are marked with an *.
  12. #                The available tasks are listed below in order:
  13. #
  14. #
  15. #            Initialization Tasks:
  16. #                InitControlGlobals()
  17. #                PrintGlobalValues()
  18. #
  19. #            Logging Tasks:
  20. #                LogStr(str, LogPriority)
  21. #                TargetInfo(theList)
  22. #                MatchApp(logMe,UpdateAppTitle)
  23. #
  24. #            Keyboard Tasks:
  25. #                TypeStr(str) *
  26. #                TypeList(List,Key, TypeFinalKey) *
  27. #                KeyEq(Alias,Otherkey) *
  28. #                SpecialKey(Key, keyName, numTimes) *
  29. #
  30. #            Control Tasks:
  31. #                SelectMenuItem(menuName1, menuName2, menuName3)                    
  32. #                FindMenu(theMenuItem)
  33. #                SelectButton(ButtonName)
  34. #                SelectRadioButton(RadioButtonName)
  35. #                SelectCheckBox(CheckBoxName)
  36. #                CheckYesNo(flag)
  37. #
  38. #            Window Tasks:
  39. #                DialogCheck(FindStaticText, CommitButton, LogIT)
  40. #                FindWindow(specifier)
  41. #                SelectWindow(specifier)
  42. #                DragWindow(h,v,specifier,absolutely)
  43. #                SizeWindow(X,Y,specifier,absolutely)
  44. #                ZoomWindow(specifier)
  45. #                ScrollWindow(foo,x,y)
  46. #                GetVHScrollBars()
  47. #                CloseWindow(howClose, overwrite, specifier, DocName)
  48. #
  49. #            Mouse Tasks:
  50. #                MoveRelativeToWindow(x, y, specifier, mouseDown, inset) *
  51. #                MoveMouse(x, y, absolutely , mouseDown) *
  52. #
  53. #            File Related Tasks:
  54. #                NameOK(NameDoc, replaceFlag,SelectSaveAs,PathList)
  55. #                OpenDoc(namedoc, SelectOpen. PathList) *
  56. #                SF_Navigate( PathList,TEToggle, FinalReturn) 
  57. #                SF_Type(PathList,TEToggle, FinalReturn)
  58. #                ReplaceExist( replaceFlag, NameDoc) 
  59. #                GetNewFileName(name)    
  60. #
  61. #            Launch Tasks:
  62. #                Twitcher(appName)
  63. #                MiniLaunch(appTitle, LaunchApp, SetDir)
  64. #                LaunchTwitch(AppName, AliasDir, LaunchApp, SetDir)
  65. #                PatchLaunchTwitcher(AppName, AliasDir, LaunchApp,SetDir) 
  66. #
  67. #            String Tasks:
  68. #                IsSubString(str1, str2)
  69. #                FindPos(char, str, startPos)
  70. #                Substring(String,StartChar,NumChar)
  71. #
  72. #            Drawing/Tool Tasks:
  73. #                DrawShapeFrame(spec, ltrb, inset)
  74. #                 SelToolFromWindow(the_tool, WindSpecifier, WhichToolStr)
  75. #                SelToolFromPallette(the_tool, WindSpecifier, WhichToolStr)
  76. #                DoDraw(PaletteType)
  77. #                DoText (NextLineKey, Specifier, inset)
  78. #
  79. #            Misc. Tasks:
  80. #                PageSetup(WhichDevice)
  81. #                Printer() 
  82. #                GetXYRandom(inset, specifier)
  83. #                IsNumber(whatAmI)
  84. #                PtInRect(thePoint,theRect)
  85. #                CenterOfScreenClick()
  86. #                RemoveItem(Item,list)
  87. #                ReplaceItem(ItemtoBeReplaced, ReplaceItem,List)
  88. #                Timer(timeParam) begin
  89. #                ETime(time1, time2) begin
  90. #                DoSpecialTest( WhichTest ) 
  91. #                Scrapbook(requestElement, ccpFlag, pasteFlag) *
  92. #                Quit(OverWrite,DocName,HowQuit)
  93. #
  94. #     Copyright Apple Computer, Inc. 1985-1991
  95. #    All rights reserved
  96. #===============================================================================
  97. #     NJV/KTA    5/23/90        Created version 2.03
  98. #    NJV/KTA 7/20/90        Modified to 2.1. - For more info about tasks that
  99. #                        have changed since 2.03 the changes please refer to  
  100. #                        the task header. These changes should not affect your
  101. #                        current scripts. The fixes were for added functionality.
  102. #                        Globals were added for disabling individual features of 
  103. #                        LogStr.
  104. #                            LogStr()
  105. #                            TargetInfo()        (New)
  106. #                            MatchApp()
  107. #                            TypeList()             (New)
  108. #                            SpecialKey()
  109. #                            CheckYesNo()
  110. #                            SizeWindow()
  111. #                            ScrollWindow()
  112. #                            GetVHScrollBars()     (New)
  113. #                            CloseWindow()
  114. #                            MoveRelativeToWindow()
  115. #                            MoveMouse()
  116. #                            NameOK()
  117. #                            OpenDoc()
  118. #                            Scrapbook()
  119. #                            IsSubString()         (New)
  120. #                            FindPos()             (New)
  121. #    DM     9/18/90        Modified to 2.2. - Added DoSpecTest() and calls to include
  122. #                        Cdev.lib.vu and DA.lib.vu
  123. #    DM     9/24/90        Modified CloseWindw, MoveRelativeToWindow and GetXYRandom.
  124. #                        All calls are preserved except GetXYRandom. Added
  125. #                        general version of DrawShapeFrame.
  126. #    NJV    10/9/90            Bug fix in Scrapbook for 6.0 world
  127. #    NJV    11/27/90        Updated to version 2.4b3 by making the following changes:
  128. #                            + Docname wasn't explained in CloseWindow()
  129. #                            + Header for Quit() needed to be fixed
  130. #                            + Header for FindWindow() needed to be fixed
  131. #                            + Header for Opendoc() needed to be fixed
  132. #                            + Header for ScrapBook() needed to be fixed
  133. #                            + Header for NameOK() needed to be fixed
  134. #                            + Full names were taken out of headers
  135. #                            + bug fix and header update in SpecialKey()
  136. #                            + updated LaunchTwitch() and MiniLaunch() for new
  137. #                                version of MiniLauncher 1.3b
  138. #    NJV/KTA    12/18/90    Combined changes from 2 updated versions of Controls.lib
  139. #    KTA        12/20/90    Fixed bug in AppVerify scheme which included changes to
  140. #                        LaunchTwitch, LogStr, MatchApp
  141. #                        Also updated NameOK to handle dialog change in 7.0
  142. #    KTA     1/2/91        Added global BuildVers.
  143. #    KTA     1/8/91        Changed Scrapbook, Quit
  144. #    NJV/KTA 1/24/91        2.5b4 - Modified LaunchTwitch, Added check for warfare,
  145. #                        included Library include of Integrate.lib, added
  146. #                        code to support Integrate library
  147. #    NJV        1/28/91        Modified LaunchTwitch to disable integration
  148. #    KTA        2/5/91        Added DialogCheck for checking statictext in Dialogs
  149. #    KTA        2/18/91        InitControlGlobals() - added outputting of Global values.
  150. #                        Quit() - while(checkYesNo)
  151. #                        ScrapBook() - Global Integration := 0
  152. #                        LogStr() - Added LineItemTest
  153. #                        LogStr() - Took out Integration if DisableAllLogging
  154. #    NJV        3/28/91        2.5b5 - Updated Headers, changed LaunchTwitch,
  155. #                            added PrintGlobals()
  156. #    NJV        6/25/91        Added PtInRect routine, modified ZoomWindow for
  157. #                            better error checking, modified IsNumber to
  158. #                            use VU's new TypeOf function.
  159. #    KTA        7/10/91        Added Standard File stuff SF_Type and SF_Navigate
  160. #                        Modified NameOK and OpenDoc
  161. #                        Modified GetNewFileName
  162. #    KTA        7/26/91        global SF_PUTLocation;
  163. #                        global LogLevel;
  164. #                        global PatchLaunchTwitch;
  165. #    KTA        8/3/91        global ScrapTEXT;
  166. #                        global ScrapPICT;
  167. #                        global AliasDirectory;
  168. #                        Added parameter to PageSetup()
  169. #    KTA        8/19/91        Added more Globals and DoText Task 
  170. #                        DragWindow('RandomReturn');
  171. #    KTA        8/21/91        Timer(4) := CurrentTime
  172. #    KTA        9/05/91        Added Specifier = 0  for DoText
  173. #                        Added Global Printer
  174. #    KTA        9/17/91        Added ReplaceItem(), RemoveItem(),
  175. #                        SelToolFromWindow(),SelToolFromPallette()
  176. #    KTA        9/21/91        Updated DoText() - Added FindMenu()
  177. #    KTA        9/22/91        Updated SelectButton(),SelectCheckBox(),SelectRadioButton()
  178. #    KTA        10/29/91    Added Global DrawWindow to DoDraw().
  179. #                        Fixed problem in GetXYRandom() when passing string as Specifier.
  180. #    KTA        11/15/91    Fixed LaunchTwitch memory check
  181. #    JM        2/3/92        ZoomWindow:  Fixed failure on multiple monitors
  182. #    JM        2/3/92        CloseWindow:  Fixed bogus error on dirty-save.
  183. #    JM        2/6/92        IsSubStr:  Added '=' clause
  184. #    ML        2/12/92        Updated DoText() - added inset parameter
  185. #    JM        2/14/92        Fixed Timer(4) for hours between 12AM and 1AM
  186. #    JM        2/25/92        Twitcher(): Added '~' in 'Hide' exception.
  187. #                        SubString(): Added space between 'Card' and 'String'.
  188. #    KTA        4/14/92        Removed project specific calls
  189. #    KTA        4/14/92        Reimplemented 6.0.x launching mechanism (minilaunch)
  190. #    KTA        4/15/92        Reimplemented 6.0.x Standard File support
  191. #    KTA        4/20/92        Implemented support for International (ordinality)
  192. #    ML        4/21/92        FindWindow(): Added error check for screen ordinality
  193. #                        GetXYRandom(): Optimized using FindWindow()
  194. #                        SelToolFromPallette(): Revised for compatibility to VU 2.0
  195. #                        SelToolFromWindow(): Revised for compatibility to VU 2.0
  196. #                        DoDraw(): Revised for compatibility to VU 2.0
  197. #                        ZoomWindow(): Revised for compatibility to VU 2.0
  198. #    KTA        4/21/92        Added support for pointlists in MoveMouse(), 
  199. #                        MoveRelativeToWindow(), and GetXYRandom()
  200. #########################################################################
  201.  
  202. #########################################################################
  203. ####################            GLOBALS                #####################
  204. #########################################################################
  205. ### Global Library Definitions
  206. ###        If current value is 0 or 1, new value must be a 0 or 1
  207. ###        If current value is true or false, new value must be true or false
  208. ###        If current value is a string, new value must be a string
  209. ###
  210. #########################################################################
  211. #########################################################################
  212. #                            InitControlGlobals()
  213. #========================================================================
  214. # Author:        NJV
  215. # Description:    Initializes all global variables used by the Controls.lib
  216. #                library.  This task should be called immediately after
  217. #                the "Libaries 'Control.lib';" line in the script.  It
  218. #                is OK to modify the values of some of the variables.  This is 
  219. #                how you customize your VU scripting environment and the way
  220. #                that your scripts will react using this library.
  221. # Parameters:    None
  222. # Returns:        Nothing
  223. # Examples:        InitControlGlobals();
  224. # Assumptions:    That you understand what the global does before resetting it. 
  225. ################################################################################
  226. ########### It is OK to modify the following GLOBAL Settings -  Be      ###########
  227. ########### careful that you understand what the Global is used for  ###########
  228. ################################################################################
  229. #========================================================================
  230. # History:
  231. #    NJV        3/28/91        Created
  232. #########################################################################
  233. Task InitControlGlobals() begin
  234.     println "Initializing Globals in the Controls.lib 3.0.15";
  235.     
  236.     ############## Misc Globals ############
  237.     global LogLevel := 5;                    # Specifies the which logstr calls will be output
  238.     global PatchLaunchTwitch := 0;
  239.     global BugsOn := 0;                        # if set to 1 any known bugs which check this global will be regressed
  240.     global Spectest := 0;                    # To begin any special tests designated in 
  241.     global AppVerify := 1;                    # 1 to verify the application is expected
  242.     global TargetInfoDescriptor := 'Target';    # Descriptor to use 'Target' is the one only defined currently
  243.     global TargetCheck := 2;                # 1 for target title; 2 for target application title
  244.         
  245.     #################################
  246.     # Value for integration variable sets approximate number of LogStr calls 
  247.     # per Integration call. The ratio of integrate()/LogStr() = 1/Integration.
  248.     #################################        # Random CDEV/DA testing
  249.     global Integration := 0;                # Integration module requires Integration.lib and ShimSquad.lib
  250.                                             # Only call is in LogStr() verify the call is uncommented.
  251.  
  252.     ############## Font Globals ############
  253.     global FontList         :=    {"Courier","Helvetica","Times"};
  254.     global FontSizeList     :=    { '10','12','14','18','24' };
  255.     global FontStyleList    :=    { 'Plain','Bold','Italic','Outline' };
  256.     global TextStr             :=     "How piqued razorback frogs can level six jumping gymnasts, Jim!";
  257.     
  258.     ############## Tool Global  ############
  259.     global ToolMultiplier := 1;            # Times to excercise an applications tools
  260.  
  261.     ############## ScrapBook Globals ############
  262.     global ScrapTEXT := 1;                # ScrapItem location of TEXT
  263.     global ScrapPICT := 2;                # ScrapItem location of PICT
  264.     global ScrapStyledTEXT := 0;
  265.     global ScrapColorPICT := 0;
  266.     global ScrapICON := 0;
  267.     global ScrapSOUND := 0;
  268.     global ScrapMOVIE := 0;
  269.     
  270.     ############## Script Globals ############
  271.     global AliasDirectory := "#CoreAliases";        # Location of Core app aliases ( found in Apple Menu )
  272.     global AliasDirectory2 := "#Tier 1-2 Aliases";    # Location of nonCore app aliases ( found in Apple Menu )
  273.  
  274.     ############################################################################
  275.     # SF_PutLocation contains the path to the directory in which files will be saved
  276.     # by the NameOK task. If the list is empty files will be saved in the default dir
  277.     # IMPORTANT:  SF_PUTLocation is a list
  278.     # for example:  global SF_PUTLocation := {"myDisk"};
  279.     ############################################################################
  280.     global SF_PUTLocation := {};
  281.  
  282.     ############## Print Global  ############
  283.     global PrintTest := 0;                            # If true print test will be executed
  284.     
  285.     ############################################################################
  286.     ####### DO NOT modify any of the following GLOBAL Settings -      ############
  287.     ####### DisableAllLogging may be reset during script execution  ############
  288.     ############################################################################
  289.         match[system v:?Sysname];    # Match system build
  290.         if (Sysname >= /7.0/)
  291.             Global isSys7 := True;
  292.         else
  293.             Global isSys7 := False;
  294.     global BuildVers := "{Sysname}"; 
  295.     global LogStrCount := 0;        # Initializes the counter used by LogStr
  296.     global LastSavedFile;            # Contains the name of the last file saved from NameOK();
  297.     global AppTitle := "";            # Current application title for AppVerify()
  298.     global PrevAppTitle := "";        # Previous application title (for twitching back)
  299.     global DisableAllLogging := 0;    # 1 if no logging (run time modify only)
  300.     if (global DisableAllLogging)
  301.         Global LogLevel := 0;
  302.     global SF_OriginalPath := {};    # Holds pathlist of Standard File before you navigate
  303.     PrintGlobals();                    # print the global values to output
  304.     println;
  305. end;                                    
  306.  
  307.  
  308. #########################################################################
  309. #                            PrintGlobals()
  310. #========================================================================
  311. # Author:        NJV
  312. # Description:    Prints the values of all Control Globals
  313. # Parameters:    None
  314. # Returns:        Nothing
  315. # Examples:        PrintGlobals();
  316. # Assumptions:    None 
  317. #========================================================================
  318. # History:
  319. #    NJV        3/28/91        Created
  320. #########################################################################
  321. task PrintGlobals() begin
  322. global BuildVers;
  323.  
  324.     if (global AppVerify)
  325.         println "The 'Application Verification' scheme is turned - ON";
  326.     else
  327.         println "The 'Application Verification' scheme is turned - OFF";
  328.  
  329.     if (global TargetCheck) begin
  330.         if (TargetCheck= 1)
  331.             TCItem := "the target's 'Title'";
  332.         else if (TargetCheck= 2)
  333.             TCItem := "the title of the target's current 'Application'";
  334.         println "The global 'TargetCheck' is set to output - {TCItem}";
  335.     end;
  336.     
  337.     ############## Print Font Globals ############
  338.     if (global FontList) begin
  339.         print "The global 'FontList' is : '";
  340.         fntCount := Card(FontList);
  341.         For timeThru := 1 to fntCount begin
  342.             print FontList[timeThru];
  343.             if     not(timeThru = fntCount)
  344.                 Print "', '";
  345.         end;
  346.         Println "'";
  347.     end;
  348.     
  349.     if (global FontSizeList) begin
  350.         print "The global 'FontSizeList' is : '";
  351.         fntSZCount := Card(FontSizeList);
  352.         For timeThru := 1 to fntSZCount begin
  353.             print FontSizeList[timeThru];
  354.             if     not(timeThru = fntSZCount)
  355.                 Print "', '";
  356.         end;
  357.         Println "'";
  358.     end;
  359.     
  360.     if (global FontStyleList) begin
  361.         print "The global 'FontStyleList' is : '";
  362.         fntSTLCount := Card(FontStyleList);
  363.         For timeThru := 1 to fntSTLCount begin
  364.             print FontStyleList[timeThru];
  365.             if     not(timeThru = fntSTLCount)
  366.                 Print "', '";
  367.         end;
  368.         Println "'";
  369.     end;
  370.     
  371.     if (global TextStr) 
  372.         println "The global TextStr is set to - '{TextStr}'";
  373.             
  374.     ############## Print ScrapBook Globals ############
  375.     if (global ScrapTEXT) 
  376.         println "ScrapText is set to - '{ScrapTEXT}'";
  377.  
  378.     if (global ScrapPICT) 
  379.         println "ScrapPICT is set to - '{ScrapPICT}'";
  380.  
  381.     if (global ScrapStyledTEXT) 
  382.         println "ScrapStyledTEXT is set to - '{ScrapStyledTEXT}'";
  383.  
  384.     if (global ScrapColorPICT) 
  385.         println "ScrapColorPICT is set to - '{ScrapColorPICT}'";
  386.  
  387.     if (global ScrapICON) 
  388.         println "ScrapICON is set to - '{ScrapICON}'";
  389.  
  390.     if (global ScrapSOUND) 
  391.         println "ScrapSOUND is set to - '{ScrapSOUND}'";
  392.  
  393.     if (global ScrapMOVIE) 
  394.         println "ScrapMOVIE is set to - '{ScrapMOVIE}'";
  395.  
  396.     ############## Print Script Globals ############
  397.     if (global AliasDirectory) 
  398.         println "AliasDirectory is set to - '{AliasDirectory}'";
  399.  
  400.     if (global AliasDirectory2) 
  401.         println "AliasDirectory2 is set to - '{AliasDirectory2}'";
  402.  
  403.     if (global ToolMultiplier) 
  404.         println "The global ToolMultiplier is set to - '{ToolMultiplier}'";
  405.  
  406.     ############## Print Other Globals ############
  407.     if (global BugsOn) 
  408.         println "The global 'BugsOn' has been activated - Cross your fingers!!!";
  409.  
  410.     if (global Spectest)                         # DoSpecTestsInitial and DoSpecTestsMiddle
  411.         println "The SpecialTests are - ON. Does this effect you???";
  412.     else
  413.         println "The SpecialTests are  - 'OFF' or Disabled";
  414.  
  415.     if (global Integration)
  416.         println "Integration Testing is - 'ON' and set to '{Integration}'";
  417.     else
  418.         println "Integration Testing is - 'OFF' or Disabled";
  419.  
  420.     if (global LogLevel) 
  421.         println "LogLevel is set to '{LogLevel}'";
  422.     else
  423.         println "All logging is disabled";
  424.  
  425.     Println "The current system is - '{BuildVers}'";
  426.     
  427.     if (global SF_PUTLocation) 
  428.     begin
  429.         SFPath := "";
  430.         for each item in SF_PUTLocation 
  431.             SFPath := SFPath + Item + ":";
  432.         Println "SF_Put is set to navigate to '{SFPath}'";
  433.     end;
  434.     else
  435.         println "SF_Put will save to the default directory";
  436. end; # PrintGlobals()
  437.  
  438. #########################################################################
  439. #                    LogStr(str, errorCheck,doTargetCheck)
  440. #========================================================================
  441. # Author:        KTA
  442. # Description:    Match the target and print it with whatever is passed
  443. #                to it in the 'str' parameter.  Set the appropriate 
  444. #                LogPriority based on the context of the string.
  445. # Parameters:    str - string to be printed
  446. #                LogPriority -    The priority of the string to be printed
  447. #                0 - No logging
  448. #                1 - Errors
  449. #                2 - Comments and Notes
  450. #                3 - Summary information
  451. #                4 - More detailed
  452. #                5 - Detailed description
  453. # Returns:        Nothing
  454. # Examples:        LogStr("It worked");
  455. #                LogStr("It worked",3);
  456. # Assumptions:        None 
  457. #========================================================================
  458. # History:
  459. #    KTA        4/1/90        Created
  460. #    KTA        4/29/90        This routine now checks to make sure the global
  461. #                        AppTitle equals the current application running -
  462. #                        if not, it assumes that the target crashed and
  463. #                        aborts the script.
  464. #    NJV        5/15/90        Added errorCheck parameter for disabling error
  465. #                        checking.
  466. #    NJV        7/9/90        Added targetCheck for disabling target matching
  467. #    NJV/KTA    7/13/90        Added TargetInfo mechanism 
  468. #    KTA        7/19/90        Added key equivelant 'Q'; to quit the current app if it doesn't match
  469. #    NJV        7/24/90        Moved LogStrCount into not DisableAllLogging block
  470. #    KTA        8/2/90         Added - if not( theAppTitle ~= /≈{global AppTitle}≈/)
  471. #    NJV/KTA    12/18/90     Added - Retry for AppVerify 
  472. #    KTA        12/20/90     Reworked errorCheck to work with  new MatchApp
  473. #    KTA        2/18/91     Added LineItemTest
  474. #    KTA        2/19/91     Took out integration is DisableAllLogging is on.
  475. #    KTA        4/1/91         Changed LogStr to Print so we wouldn't recursively call logStr.
  476. #    KTA        7/26/91     Deleted parameters errorCheck and doTargetCheck (Sorry Nick)
  477. #                        Added LogPriority
  478. #    KTA        8/5/91         Changed app verification check to call to IsSubString
  479. #########################################################################
  480. task LogStr(str,LogPriority := 5) begin
  481.     global AppVerify, TargetCheck, AppTitle, LogLevel,LogStrCount,DisableAllLogging;
  482.     theStr := '';
  483.     if (TargetCheck)
  484.         theStr := TargetInfo(TargetCheck);
  485.     if (not DisableAllLogging) and (LogPriority <= LogLevel)
  486.     begin
  487.         LogStrCount := LogStrCount + 1;
  488.         println LogStrCount," - ",str," {theStr}";
  489.     end;
  490.     if (AppVerify) begin
  491.          match[application t:?theAppTitle];
  492.  
  493.         retry := 2;
  494.         while not(IsSubString(AppTitle, theAppTitle)) begin    # assume target crashed if app name not match
  495.             theAppTitle := MatchApp(0,0);
  496.             if retry begin
  497.                 retry := retry - 1;
  498.                 LaunchTwitch(AppTitle,, 0);
  499.             end;
  500.             else begin
  501.                 PressKey K:{CommandKey};
  502.                 Type k: {'q'};        # Quit
  503.                 ReleaseKey K:{CommandKey};
  504.                 Println "*** Current application: '{theAppTitle}'   *** Expected application: '{AppTitle}'";
  505.                 Println "*** Assuming the target is off track - aborting script and typing key Equivalent 'Q'";
  506.                 Println  "################### Failure ################";
  507.                 Println;
  508.                 Println;
  509.                 exit;
  510.             end;
  511.         end;
  512.     end;
  513.     #########################################
  514.     # if we are in integration mode, integrate!
  515. (*    #########################################
  516.     if (global Integration) begin
  517.         if not(DisableAllLogging) begin
  518.             if (1 = random(1,Integration)) begin    # if the random number is 1, then run integrate()
  519.                 if not(match[window o:1 s:Dialog]!)
  520.                     Integrate(1,-3,1);            # perform a random DA or CDEV test
  521.             end;
  522.         end;
  523.     end;
  524. *)
  525.     Return(1);
  526. end; # LogStr()
  527.  
  528.  
  529. #########################################################################
  530. #                            TargetInfo(theList)
  531. #========================================================================
  532. # Author:        NJV/KTA
  533. # Description:    Match whatever is specified in global TargetInfoDescriptor
  534. #                and will return the appropriate string.
  535. # Parameters:    theList[1] - what to match for - default 'Target'
  536. #                theList[2] - Specifier of what info to return
  537. #                    If theList[1] = 'Target'then    
  538. #                        if theList[2] = 
  539. #                         1 - Return Title for target
  540. #                         2 - Returns Application running on Target
  541. # Returns:        Str
  542. # Examples:        global TargetCheck := 1;    
  543. #                global TargetCheck :={1,2};
  544. #========================================================================
  545. # History:
  546. #    NJV/KTA    7/13/90     Created
  547. #    KTA        9/22/91     Only target info
  548. #########################################################################
  549. task TargetInfo(theList) 
  550. begin
  551.     theDesc := global TargetInfoDescriptor;
  552.         list2 := theList;
  553.         if (not card(list2))     # a single number
  554.             list2 := {theList};
  555.     if (theDesc = 'Target')
  556.     begin
  557.         theDescInfo := match [target t:?TargetTitle a:?App]!;
  558.         theAppTitle :=App[1].t;
  559.         
  560.         if not (theDescInfo)
  561.             return('');
  562.         
  563.         str := "(Target -";
  564.                 
  565.         for each item in list2 
  566.         begin
  567.             if (item = 1)    # title
  568.                 str := "{str} Title:∂'{TargetTitle}∂'";
  569.             else if (item = 2)    # App
  570.                 str := "{str} Application:∂'{theAppTitle}∂'";
  571.         end;
  572.             
  573.         str := "{str})";
  574.         return(str);
  575.     end;
  576. end; # TargetInfo()
  577.  
  578.  
  579. #########################################################################
  580. #                     MatchApp(logMe,UpdateAppTitle)
  581. #========================================================================
  582. # Author:            KTA
  583. # Description:        This routine will match the current Application and,
  584. #                    if the logMe parameter is 1, will log the current
  585. #                    application name by passing it to LogStr().  If a
  586. #                    parameter is not passed, the default behavior will
  587. #                    log the application's title.  This routine will also
  588. #                    set the global AppTitle to the application's title.
  589. #                    Output appears in the following format:
  590. #                            The current application is "Finder"
  591. # Parameters:        logMe - 1 to print the current application's title
  592. #                            0 not to print the application's title
  593. #                    UpdateAppTitle     - 1 to update the global AppTitle
  594. #                                    - 0 not to update global AppTitle
  595. # Return Value:        string holding current application's title
  596. # Examples:            MatchApp();
  597. # Assumptions:        there is an active application
  598. #========================================================================
  599. # History:
  600. #    KTA        3/16/90        Created 
  601. #    KTA        4/28/90        Makes a call to global Apptitle to Verify App
  602. #    KTA        5/7/90        Added parameter to allow bypassing of LogStr() call.
  603. #    NJV        5/13/90        Now returns title of application
  604. #    KTA        7/13/90        Took out initial 5 second wait
  605. #    KTA        12/20/90    Added UpdateAppTitle
  606. #    KTA        9/22/91        Ability to not update global AppTitle but still log the app
  607. #########################################################################
  608. task MatchApp(logMe := 1, UpdateAppTitle :=1) 
  609. begin
  610.     match[application t:?theAppTitle];
  611.     if (UpdateAppTitle)
  612.         global AppTitle := theAppTitle;            #to Verify App
  613.  
  614.     if (logMe)
  615.         LogStr("The current application is '{theAppTitle}'");
  616.  
  617.     return(theAppTitle);
  618. end; # MatchApp()
  619.  
  620. #########################################################################
  621. #                                TypeStr(str)
  622. #========================================================================
  623. # Author:        KTA
  624. # Description:    This routine will type whatever is passed in as the String.
  625. # Parameters:    str - string to be typed
  626. # Returns:        Nothing
  627. #========================================================================
  628. # History:
  629. #    KTA        1/20/90        Created
  630. #    KTA        1/9/91        Added default parameter ''
  631. #########################################################################
  632. task TypeStr(str :='') begin
  633.     type k:{str};
  634.     LogStr("Typed '{str}'");
  635. end; # TypeStr()
  636.  
  637.  
  638. #########################################################################
  639. #                        TypeList(List,Key, flag)
  640. #========================================================================
  641. # Author:            KTA
  642. # Description:        This routine will type each item in the {list} and the 
  643. #                    selected special key after each item. If flag = 0 the 
  644. #                    special key will be suppressed after the last item.
  645. # Parameters:        List -    list holding strings to type
  646. #                    Key    -    int representing key to type after the item has
  647. #                            been typed. 
  648. #                        key := 0 Nothing
  649. #                        key := 1 (ReturnKey)
  650. #                        Key := 2 (TabKey)
  651. #                        Key := 3 (EnterKey)
  652. #                        Key := 4 (UpArrowKey)
  653. #                    flag -     1 to type special key after last item in list
  654. #                            0 to disable typing of last special key
  655. # Return Value:        None
  656. # Examples:            TypeList({'A','list', 'of items'},2); To type each item 
  657. #                    and then the tabKey
  658. # Assumptions:        None 
  659. #========================================================================
  660. # History:
  661. # KTA        7/1/90    Created
  662. # DMM         7/2     Flag to type special key after last item
  663. # KTA        8/20/90    Added check to see if key is defined before adding 'and' to {item}
  664. # KTA        7/20/91    Check if punctuation of specialkey
  665. # KTA        9/04/91    Added UpArrow key
  666. # KTA/DM    9/22/91    Reorganized 
  667. ################################################################################    
  668. task TypeList(List,Key := 0, TypeFinalKey := 0) begin
  669.     theWholeList := card(list);
  670.     for numtimes := 1 to theWholeList 
  671.     begin
  672.         if(TypeOf(Key) = 'integer') 
  673.         begin
  674.             if (key = 1) 
  675.                 KeyList := {ReturnKey,' and the Return Key'};
  676.             else if (key = 2) 
  677.                 KeyList := {TabKey,' and the Tab Key'};
  678.             else if (key = 3)
  679.                 KeyList := {EnterKey,' and the Enter Key'};
  680.             else if (key = 4) 
  681.                 KeyList := {UpArrowKey,' and the Up Arrow Key'};
  682.         end;
  683.         else 
  684.             KeyList := {Key,' and some Special Key???'};
  685.         KeyName := KeyList[2];
  686.         Item := List[numtimes];
  687.         Type k:{ Item };
  688.         if not (numtimes = theWholeList)
  689.         begin
  690.             Type K:{KeyList[1]};
  691.         end;
  692.         else
  693.             if(TypeFinalKey)
  694.                 Type K:{KeyList[1]};
  695.             else 
  696.                 KeyName := '';
  697.         LogStr("Typed '{item}'{KeyName}");
  698.         
  699.     end;
  700. end; # TypeList()
  701.  
  702.  
  703. #########################################################################
  704. #                            KeyEq(Alias,Otherkey)
  705. #========================================================================
  706. # Author:        KTA
  707. # Description:    This routine will select the Keyboard Equiv <alias>
  708. # Parameters:    Alias -        string holding character to be typed with
  709. #                            command key down.
  710. #                OtherKey -    int representing special keys to hold down in
  711. #                            conjunction with the command key
  712. #                    1 - Shift key
  713. #                    2 - Option key
  714. # Returns:        None
  715. # Examples:        KeyEq("q");
  716. #========================================================================
  717. # History:
  718. #    KTA        4/1/90        Created
  719. #    KTA        7/31/90        Added MatchApp for 'w' and 'q'
  720. #    KTA/PF    8/14/90        Added Shift key Functionality
  721. #    KTA        8/16/90        Added Option key Functionality
  722. #     KTA        9/22/91        Optimized -took out cases for 'w' and 'q'
  723. #########################################################################
  724. task KeyEq(Alias,Otherkey := 0) begin
  725.     KeyList := { '',''};
  726.     if (Otherkey =1) 
  727.         KeyList := {ShiftKey,'-Shift'};
  728.     else if (Otherkey = 2) 
  729.         KeyList := {Optionkey,'-Option'};
  730.  
  731.     pressKey k:{ commandKey,KeyList[1]};
  732.     type k : { alias };
  733.     releaseKey k:{ commandKey,KeyList[1] };
  734.     WhichKey := KeyList[2];
  735.     LogStr("Pressed the ∂('{alias}'∂) key and the Command{WhichKey} key");
  736. end; # KeyEq()
  737.  
  738.  
  739. #########################################################################
  740. #                        SpecialKey(Key,keyName,n)
  741. #========================================================================
  742. # Author:        KTA
  743. # Description:    This routine will type whatever SpecialKey is entered
  744. #                However it will only log the name of the special character 
  745. #                if the special key name is also passed in as a String in
  746. #                the keyName parameter.
  747. # Parameters:    Key - the VU key-word for the special key to be typed
  748. #                keyName - the string name of the special key
  749. #                n - number of times to type the special key (default = 1)
  750. # Returns:        Nothing
  751. # Examples:        SpecialKey(TabKey,"TabKey");
  752. #========================================================================
  753. # History:
  754. #    KTA        4/25/90        Created
  755. #    KTA     7/5/90        Added n parameter for number of times to be completed.
  756. #    NJV        11/27/90    bug fix - if no keyName and n > 1, then str was typed
  757. #                        every time instead of once.  Also updated header.
  758. #    KTA     9/22/91        Added StrExt instead of another if statement
  759. #########################################################################
  760. task SpecialKey(Key,keyName:="",numTimes :=1) begin
  761.     StrExt :=  "";
  762.     for x := 1 to numTimes
  763.         type k:{ Key };
  764.     if (numTimes <> 1)
  765.         StrExt :=  "- ({numTimes}) times";
  766.  
  767.     if (keyName ="")
  768.         LogStr("Typed some special key {StrExt}");
  769.     else
  770.         LogStr ("Typed {keyName} {StrExt}");
  771. end; # SpecialKey()
  772.  
  773.  
  774. ########################################################################
  775. #                 SelectMenuItem(menuName1, menuName2, menuName3)                    
  776. #=======================================================================
  777. # Author:           SL
  778. # Description:        Selects the menu item by its name.
  779. # Parameters:        menuName1 := Menu item to be selected.
  780. #                    menuName2 := Menu name if non-hier menu and
  781. #                                 Level 2 menu item if hier menu.
  782. #                    menuName3 := "" if non-hier menu.
  783. #                                 Menu name if hier menu.
  784. # Returns:            menuTitle - MenuItem name that selection was successful
  785. #                    0 - Couldn't select menu item
  786. # Notes:                Do not have to pass 'menuName2' or 'menuName3'
  787. #                    as a parameter.  In that case, default value, "",
  788. #                    will be used.
  789. #=======================================================================
  790. # History:
  791. #    SL        4/4/90        Created
  792. #    KTA        5/16/90        MatchApp Verification
  793. #    KTA        8/7/90        Return menuTitle
  794. #    KTA        4/7/92        Support selection by ordinality
  795. ########################################################################
  796. task SelectMenuItem(menuName1, menuName2 := "", menuName3 := "") 
  797. begin
  798.     if (Typeof(menuName1) = 'string')
  799.     begin
  800.         if (menuName3 = "")                    # Match non-hier menus            
  801.             ourMenuItem := match [menuItem t: menuName1 m:[menu t: menuName2]];
  802.         else                        # Match hier menus                
  803.             ourMenuItem :=match [menuItem t:menuName1 
  804.                                           m:[menuitem t:menuName2 
  805.                                           m:[menu t:menuName3]]];
  806.     end;
  807.     else
  808.     begin
  809.         if not(menuName3)                    # Match non-hier menus            
  810.             ourMenuItem := match [menuItem o:menuName1 m:[menu o:menuName2]];
  811.         else                        # Match hier menus                
  812.             ourMenuItem :=match [menuItem o:menuName1 
  813.                                           m:[menuitem o:menuName2 
  814.                                           m:[menu o:menuName3]]];
  815.     end;
  816.  
  817.     if (ourMenuItem)             # Not there
  818.     begin
  819.         if (ourMenuItem.e)         #  enabled
  820.         begin
  821.             select ourMenuItem!;
  822.             menuTitle := ourMenuItem.t;
  823.             LogStr("Selected the '{menuTitle}' menu item");
  824.             return(menuTitle);
  825.         end;
  826.         else 
  827.         begin
  828.             LogStr("!@#$% Menu item {menuName1} is not enabled to select.");
  829.             return(0);
  830.         end;
  831.     end;
  832.     else 
  833.     begin
  834.         LogStr("!@#$% Could not find menu item {menuName1} to select");
  835.         return(0);
  836.     end;
  837. end; # SelectMenuItem()
  838.  
  839. #########################################################################
  840. #                             FindMenu(theMenuItem)
  841. #=======================================================================
  842. # Author:              KTA
  843. # Description:        Returns the Menu(s) in which theMenuItem is contained.
  844. # Parameters:        theMenuItem    :=    the menuitem to be searched for.
  845. # Returns:            0    -    Can't match theMenuItem.
  846. #                    {theMenu,""}    -    for a nonHierarchical menu.
  847. #                    {theHMenuItem, theMenu}    -    if its hierarchical.
  848. # Example:            MyMenu := FindMenu('Paste');
  849. #=======================================================================
  850. # History:
  851. #     KTA            9/21/90        Created
  852. #########################################################################
  853. task FindMenu(theMenuItem)
  854. begin
  855.     MenuName := match[menuitem t:theMenuItem];
  856.     if (MenuName)
  857.     begin
  858.         IsMenu := descType(MenuName.m);
  859.         if (IsMenu = 'menu')
  860.         begin
  861.             theMenu := MenuName.m.t;
  862.             Return({theMenu,""});
  863.         end;
  864.         else If (IsMenu = 'menuItem')
  865.         begin
  866.             theHMenuItem := MenuName.m.t;
  867.             MenuName := match [menuItem t:theMenuItem 
  868.                                               m:[menuitem t:theHMenuItem 
  869.                                                              m:[menu t:?theMenu]]];
  870.             Return({theHMenuItem, theMenu});
  871.         end;
  872.     end;
  873.     else Return(0);
  874. end; # FindMenu()
  875.  
  876. #########################################################################
  877. #                        SelectButton(ButtonName)
  878. #========================================================================
  879. # Author:        KTA
  880. # Description:    This routine will select the button named (ButtonName)
  881. # Parameters:    ButtonName - string holding name of button to select
  882. # Returns:        0 - Couldn't select button
  883. #                ButtonName - Selected button OK
  884. #========================================================================
  885. # History:
  886. #    KTA        3/20/90        Created
  887. #    NJV        5/13/90        Added checking to assure button is enabled
  888. #    DM        7/22/91        Dammit
  889. #    KTA        9/22/91        One match instead of two
  890. #########################################################################
  891. task SelectButton(ButtonName) begin
  892.     IsButton := match[button t:ButtonName]!;
  893.     if (IsButton)
  894.     begin
  895.         if (IsButton.e) 
  896.         begin
  897.             Select [button t:ButtonName]!;
  898.             LogStr("Selected button titled '{ButtonName}'");
  899.             return(ButtonName);
  900.         end;
  901.         else 
  902.             str := "!@#$% Couldn't select button named '{ButtonName}' because it's not enabled";
  903.     end;
  904.     else
  905.         str:= "!@#$% There was no button named '{ButtonName}'";
  906.  
  907.     LogStr(str);
  908.     return(0);
  909. end; # SelectButton()
  910.  
  911. #######################################################################
  912. #                    SelectRadioButton(RadioButtonName)
  913. #========================================================================
  914. # Author:        KTA
  915. # Description:    This routine will select RadioButton named (RadioButtonName)
  916. # Parameters:    RadioButtonName - string name of radio button to select
  917. # Returns:        0 - Couldn't select radio button
  918. #                RadioButtonName - Selected button OK
  919. #========================================================================
  920. # History:
  921. #    KTA        3/20/90        Created    
  922. #    NJV        5/13/90        Added checking to assure radio button is enabled
  923. #    KTA        9/22/91        One match instead of two
  924. #########################################################################
  925. task SelectRadioButton(RadioButtonName) begin
  926.     IsRadioButton := match [RadioButton t:RadioButtonName]!;
  927.     if (IsRadioButton) 
  928.     begin
  929.         if (IsRadioButton.e) 
  930.         begin
  931.             Select [RadioButton t:RadioButtonName];
  932.             LogStr("Selected radio button titled '{RadioButtonName}'");
  933.             return(RadioButtonName);
  934.         end;
  935.         else
  936.             str := "!@#$% Couldn't select radio button named '{RadioButtonName}' because it's not enabled";
  937.     end;
  938.     else
  939.         str:= "!@#$% There was no radio button named '{RadioButtonName}'";
  940.     LogStr(str);
  941.     return(0);
  942. end; # SelectRadioButton()
  943.  
  944. #########################################################################
  945. #                        SelectCheckBox(CheckBoxName)
  946. #========================================================================
  947. # Author:        KTA
  948. # Description:    This routine will select CheckBox named (CheckBoxName)
  949. # Paramters:    CheckBoxName - string name of check box to select
  950. # Returns:        0 - Couldn't select check box
  951. #                CheckBoxName - Selected check box OK
  952. #========================================================================
  953. # History:
  954. #    KTA        3/20/90        Created    
  955. #    NJV        5/13/90        Added checking to assure check box is enabled
  956. #    KTA        9/22/91        One match instead of two
  957. #########################################################################
  958. task SelectCheckBox(CheckBoxName) begin
  959.     isSelectCheckBox := match [CheckBox t:CheckBoxName]!;
  960.     if (isSelectCheckBox)
  961.     begin
  962.         if (isSelectCheckBox.e)
  963.         begin
  964.             Select [CheckBox t:CheckBoxName];
  965.             LogStr("Selected check box titled '{CheckBoxName}'");
  966.             return(CheckBoxName);
  967.         end;
  968.         else 
  969.             str := "!@#$% Couldn't select check box named '{CheckBoxName}' because it's not enabled";
  970.     end;
  971.     else
  972.         str:= "!@#$% There was no check box named '{CheckBoxName}'";
  973.  
  974.     LogStr(str);
  975.     return(0);
  976. end; # SelectCheckBox()
  977.  
  978.  
  979. #########################################################################
  980. #                CheckYesNo(flag, DocName)
  981. #========================================================================
  982. # Author:        SL
  983. # Description:    Checks for dialog boxes with "Yes" (or "OK") and "No"
  984. #                buttons. If they are found, clicks one of the buttons
  985. #                depending on the 'flag' parameter.
  986. # Parameters:    flag -    TRUE - Selects "Yes"  or "OK" button.
  987. #                        FALSE - Selects "No" button.
  988. #                DocName - Name that docment will be saved with.
  989. # Returns:        What is returned by SelectButton
  990. #========================================================================
  991. # History:
  992. # SL        4/3/90        Created
  993. # KTA/NV    7/17/90        Added DocName parameter for Nameok
  994. # KTA        4/15/91        took out an arbitrary Returnkey.
  995. # KTA        9/22/91        IF statements before matching - so we don't match 
  996. #                        when it's unnessecary
  997. # KTA        9/26/91        Took out call to NameOK and the DocName parameter
  998. #                        Added return values. Calling routines should call
  999. #                        NameOK based on the return Values if appropriate.
  1000. #########################################################################
  1001. task CheckYesNo(flag := true)
  1002. begin
  1003.     if ( Flag )  begin
  1004.         yesBtn := match[button t:"Yes" w:[window o:1]]!;
  1005.         okBtn  := match[button t:"Ok"  w:[window o:1]]!;
  1006.     
  1007.         if (yesBtn)
  1008.             return(SelectButton("Yes"));
  1009.         else if (okbtn)
  1010.             return(SelectButton("OK"));
  1011.     end;
  1012.     else
  1013.     begin
  1014.         noBtn  := match[button t:"No"  w:[window o:1]]!;
  1015.         if (noBtn)
  1016.             return(SelectButton("No"));
  1017.     end;
  1018. end; # CheckYesNo()
  1019.  
  1020. ########################################################################
  1021. #                        DialogCheck(FindStaticText,CommitButton)
  1022. #=======================================================================
  1023. # Author:        KTA
  1024. # Description:    This routine will to match a dialog of ordinality 1,
  1025. #                with StaticText - {FindStaticText}, if found it will select the 
  1026. #                Button - {CommitButton}.
  1027. # Parameters:    FindStaticText - StaticText string that you want to match
  1028. #                CommitButton   - Button to select if the static text is found.
  1029. # Returns:        1 - Found FindStaticText and selected CommitButton
  1030. #                0 - Couldn't find FindStaticText
  1031. #=======================================================================
  1032. # History:
  1033. #     KTA        2/5/91        Created
  1034. #     KTA        2/19/91        
  1035. #     KTA        4/1/91        Added      c:false to dialog check
  1036. #     KTA        8/6/91        Added LogIT parameter
  1037. ########################################################################
  1038. task DialogCheck(FindStaticText :='', CommitButton :="", LogIT := 1) 
  1039. begin
  1040.     DialogWin :=  collect[staticText w:[window o:1 s:dialog c:false]!]!; 
  1041.     if (DialogWin) 
  1042.     begin
  1043.         for each StaticItem in DialogWin 
  1044.         begin
  1045.         theStaticText :=  StaticItem.t;
  1046.             if not( theStaticText = '') 
  1047.             begin
  1048.                 if(IsSubString(FindStaticText, theStaticText)) 
  1049.                 begin
  1050.                     if (LogIT) 
  1051.                         LogStr("Found Dialog: '{theStaticText}'");
  1052.                     if (CommitButton)
  1053.                         SelectButton(CommitButton);
  1054.                     return(theStaticText);
  1055.                 end;
  1056.             end;
  1057.         end;
  1058.     end;
  1059.     else 
  1060.         return(0);
  1061. end;  # DialogCheck()
  1062.  
  1063. #########################################################################
  1064. #                            FindWindow(specifier)
  1065. #========================================================================
  1066. # Author:        DM
  1067. # Description:    FindWindow will return the descriptor of the window
  1068. #                specified by the parameter specifier.
  1069. # Parameters:    specifier - if string, then it holds title of window
  1070. #                            if integer, then it holds ordinality of window
  1071. # Returns:        0 - Couldn't find the window
  1072. #                1 - found the window OK
  1073. # Example:        FindWindow(1);
  1074. #========================================================================
  1075. # History:
  1076. #    DM        9/27/90        Created
  1077. #    NJV        11/27/90    Added documentation
  1078. #    ML        4/8/92        Added error check for screen ordinality if
  1079. #                        specifier < 0
  1080. #########################################################################
  1081. task FindWindow(specifier := "None") begin
  1082.     if(specifier = "None") 
  1083.     begin
  1084.         LogStr("Null specifier passed as a parameter to FindWindow");
  1085.         return (0);
  1086.     end;
  1087.     if not (TypeOf(specifier) = 'integer') 
  1088.     begin
  1089.         theDesc := match [window t:specifier]!;
  1090.         if (not theDesc) 
  1091.         begin
  1092.             LogStr("!@#$% Couldn't match a window of title {specifier}");
  1093.             return(0);
  1094.         end;
  1095.     end;
  1096.     else if(specifier > 0) 
  1097.     begin
  1098.         theDesc := match[window o:specifier]!;
  1099.         if (not theDesc) 
  1100.         begin
  1101.             LogStr("!@#$% Couldn't match a window of ordinality {specifier} with a grow box");
  1102.             return(0);
  1103.         end;
  1104.     end;
  1105.     else if(specifier = 0) 
  1106.     begin
  1107.         theDesc := match[window c:true g:true]!;
  1108.         if (not theDesc) 
  1109.         begin
  1110.             LogStr("!@#$% Couldn't match a window with a close and grow box");
  1111.             return(0);
  1112.         end;
  1113.     end;
  1114.     else if (specifier < 0) 
  1115.     begin
  1116.         scrList := collect[screen]!;
  1117.         theDesc := scrList[-specifier];
  1118.         if (not theDesc) 
  1119.         begin
  1120.             scrOrd:=-specifier;
  1121.             LogStr("!@#$% Couldn't match a screen with ordinality {scrOrd}");
  1122.             return(0);
  1123.         end;
  1124.     end;
  1125.     return (theDesc);
  1126. end; # FindWindow()
  1127.  
  1128. ########################################################################
  1129. #                        SelectWindow(specifier)
  1130. #=======================================================================
  1131. # Author:        NJV
  1132. # Description:    This routine will select a window specified by
  1133. #                ordinality or title.
  1134. # Parameters:    specifier -    holds the title or ordinality of window to
  1135. #                            select.
  1136. # Returns:        1 - Selected window OK
  1137. #                0 - Couldn't find window to select
  1138. #=======================================================================
  1139. # History:
  1140. #     NJV        4/7/90        Created
  1141. #    NJV        5/13/90        Condensed two parameters to one
  1142. #    DM        9/27/90        Optimized and added FindWindow
  1143. #    ECH        11/7/90        Changed default parameter to 0 to let FindWindow
  1144. #                        do its work.
  1145. #    DM/KA    9/30/91        Let FindWindow() handle errors
  1146. ########################################################################
  1147. task SelectWindow(specifier := 0) begin
  1148.     noErrorFlag := 0;            # Init error condition
  1149.     theWind := FindWindow(specifier);
  1150.     if theWind begin
  1151.         windOrd := theWind.o;
  1152.         title := theWind.t;
  1153.         select [window o:windOrd t:title]!;
  1154.         LogStr("Selected window of ordinality {windOrd} (titled '{title}')");
  1155.         noErrorFlag := 1;
  1156.     end;
  1157.     else 
  1158.         LogStr("!@#$% Couldn't select the window");
  1159.     return(noErrorFlag);
  1160. end;  # SelectWindow()
  1161.  
  1162.  
  1163. #########################################################################
  1164. #                DragWindow(h,v,specifier,absolutely)
  1165. #========================================================================
  1166. # Author:        KTA
  1167. # Description:    This routine will drag the specified window
  1168. #                'h' pixels horizontally (-h drags left) and 'v' pixels
  1169. #                vertically (-v drags up)
  1170. # Parameters:    h    - Horizontal pixel offset to drag the window
  1171. #                v    - Vertical pixel offset to drag the window
  1172. #                specifier - holds title or ordinality of window to drag
  1173. #                absolutely -    1 if absolute drag
  1174. #                            0 if relative drag
  1175. # Returns:        1 - Dragged window OK
  1176. #                0 - Couldn't find window to drag
  1177. #========================================================================
  1178. # History:
  1179. #    KA        4/6/90        Created
  1180. #     NJV        4/7/90        Allows for dragging by title or ordinality
  1181. #     NJV        4/26/90        Changed to allow for absolutely or relative drag
  1182. #    NJV        5/13/90        Condensed parameter list
  1183. #    DM        9/27/90        Optimized and added FindWindow
  1184. #                        Changed specifier default to 0 so it will match the 
  1185. #                        first document window.
  1186. #    KTA        8/19/91        Added RandomReturn
  1187. #    DM/KA    9/30/91        Let FindWindow() handle errors
  1188. #########################################################################
  1189. task DragWindow(h := "Random", v := "Random", specifier := 0,absolutely := 1) 
  1190. begin
  1191.     noErrorFlag := 0;            # Init error condition
  1192.     if (h = "Random") or (h = "RandomReturn") 
  1193.     begin                                # user wants random coordinates
  1194.         if (h = "RandomReturn")
  1195.             RandReturn := 1;
  1196.         xyRandom := getXYRandom(,-1);
  1197.         h := xyRandom[1];
  1198.         v := xyRandom[2];
  1199.     end;
  1200.  
  1201.     theWind := FindWindow(specifier);
  1202.     if (theWind) begin
  1203.         windOrd := theWind.o;
  1204.         title := theWind.t;
  1205.  
  1206.         if (specifier > 0)
  1207.             Str1 := "of ordinality {specifier} ";
  1208.         else if (specifier = 0)
  1209.             Str1 := "with grow and zoom box ";
  1210.         else if( not IsNumber(specifier))
  1211.             Str1 := "";
  1212.         if (RandReturn)         # Save original coordinates
  1213.         begin
  1214.             origH := theWind.r[1];
  1215.             origV := theWind.r[2];
  1216.         end;            
  1217.         if (absolutely) 
  1218.         begin
  1219.             drag [window o:windOrd t:title]! a:{h,v};                        #To drag the window
  1220.             str := "Dragged window {Str1}titled '{title}' to absolute location ∂({h},{v}∂)";
  1221.         end;
  1222.         else 
  1223.         begin
  1224.             drag [window o:windOrd t:title]! r:{h,v};                        #To drag the window
  1225.             str := "Dragged window {Str1}titled '{title}' {h} pixels horizontally and {v} pixels vertically";
  1226.         end;
  1227.         LogStr(str);
  1228.         if (RandReturn)             #Move back to orignial location
  1229.         begin
  1230.             drag [window o:windOrd t:title]! a:{origH,origV};                #To drag the window
  1231.             LogStr("Dragged window titled '{title}' back to it's original location at ∂({Origh}, {Origv}∂)");
  1232.         end;
  1233.         noErrorFlag := 1;
  1234.     end; 
  1235.     else 
  1236.         LogStr("!@#$% Couldn't drag the window");
  1237.     
  1238.     return(noErrorFlag);
  1239. end;  # DragWindow()
  1240.  
  1241.  
  1242. #########################################################################
  1243. #                    SizeWindow(X,Y,specifier,absolutely)
  1244. #========================================================================
  1245. # Author:        KTA
  1246. # Description:    This routine will match and resize the specified window.
  1247. #                If only the X and Y parameters are passed, the default
  1248. #                behavior will size the first window containing a grow
  1249. #                and zoom box absolutely.  If no parameters are passed,
  1250. #                then the default behavior will generate random
  1251. #                coordinates on the main screen and resize the window
  1252. #                to an absolute size.  If the user passes in the string
  1253. #                "random" for x and y and passes 0 for the absolutely
  1254. #                parameter (for a resize relative to current size),
  1255. #                then checks are performed to assure that new size will
  1256. #                not go off of the screen.  If it does, the values will
  1257. #                be adjusted so that the largest the window can be sized
  1258. #                is to the border of the screen.
  1259. # Parameters:    X,Y -    the Width and Height to resize the window
  1260. #                specifier -    title or ordinality of window to be sized
  1261. #                absolutely -    1 if resize window absolute
  1262. #                                0 if resize window relative
  1263. # Returns:        1 - Resized window OK
  1264. #                0 - Couldn't resize window
  1265. # Examples:        SizeWindow(200,400);
  1266. #========================================================================
  1267. # History:
  1268. #     NJV        11/20/89    Created    
  1269. #    KTA        1/20/90        Implemented LogStr()
  1270. #    NJV        4/26/90        Added byOrdinality, value, and absolutely parameters
  1271. #    NJV        5/14/90        Condensed byOrdinality and value into specifier parameter
  1272. #    NJV        5/15/90        Added random function
  1273. #    NJV/KTA    7/13/90        Bug fix - only checks window for zoom box under default
  1274. #    NJV        7/19/90        Cut routine size in half.
  1275. #    DM        9/27/90        Optimized and added FindWindow
  1276. #                        Changed specifier default to 0 so it will match the 
  1277. #                        first document window.
  1278. #########################################################################
  1279. task SizeWindow(x:="random", y:="random", specifier := 0, absolutely := 1) begin
  1280.     noErrorFlag := 0;
  1281.     theWind := FindWindow(specifier);
  1282.     specifier := theWind.o;
  1283.     title := theWind.t;
  1284.     if (theWind) begin    
  1285.         randomFlag := 0;
  1286.         if (x = "random") begin    # user wants to size window randomly
  1287.             xyRandom := getXYRandom(,-1);
  1288.             x := xyRandom[1];
  1289.             y := xyRandom[2];
  1290.             randomFlag := 1;
  1291.             if (not absolutely) begin        # relative - include possible negative values
  1292.                 negative := random(0,1);
  1293.                 if (negative = 1) begin
  1294.                     x := 0 - x;
  1295.                     y:= 0 - y;
  1296.                 end;
  1297.             end;
  1298.         end;
  1299.         
  1300.         # specifier = ordinality of window to size
  1301.         # title = title of window to size
  1302.         if randomFlag begin        # make sure if random numbers were generated that new window size is on screen
  1303.             theWindRect := theWind.r;
  1304.             match [screen r:?theScrnRect]!;
  1305.             if (absolutely) begin    # get Top-Left corner coord of window
  1306.                 if ((theWindRect[1] + x) > theScrnRect[3])        # x value off of screen - adjust it
  1307.                     x := theScrnRect[3] - theWindRect[1];
  1308.                 if ((theWindRect[2] + y) > theScrnRect[4])        # y value off of screen - adjust it
  1309.                     y := theScrnRect[4] - theWindRect[2];
  1310.             end;
  1311.             else begin                # size window relative - get Bottom-Right coord of window
  1312.                 if (not negative) begin
  1313.                     if ((theWindRect[3] + x) > theScrnRect[3])        # x value off of screen
  1314.                         x := theScrnRect[3] - theWindRect[3];
  1315.                     if ((theWindRect[4] + y) > theScrnRect[4])        # y value off of screen
  1316.                         y := theScrnRect[4] - theWindRect[4];
  1317.                 end;
  1318.                 ### the 20 in the equations below must be there.  This is to assure that
  1319.                 ### the window is not sized below 20 horizontally (the size box is 20 pixels,
  1320.                 ### and attempts to size smaller than that will cause VU to display an
  1321.                 ### "Out of bounds" error.
  1322.                 else begin        # negative value - must check against upper-left corner of screen
  1323.                     if ((theWindRect[3] + x - 20) < theScrnRect[1])        # x value off of screen
  1324.                         x := 20 - theWindRect[3] - theScrnRect[1];
  1325.                     if ((theWindRect[4] + y - 20) < theScrnRect[2])        # y value off of screen
  1326.                         y := 20 - theWindRect[4] - theScrnRect[2];
  1327.                 end;
  1328.             end;
  1329.         end;
  1330.         if (absolutely) begin
  1331.             size [window t:title o:specifier g:true ] W:x H:y;                        #To size the window
  1332.             match [window t:title o:specifier g:true r:?theWindRect]!;
  1333.             x := theWindRect[3] - theWindRect[1];
  1334.             y := theWindRect[4] - theWindRect[2];
  1335.             str := "Resized window '{title}' absolute {x} pixels wide and {y} pixels high";
  1336.         end;
  1337.         else begin
  1338.             if (randomFlag)    begin            # include negative offsets for random size
  1339.                 match [window t:title o:specifier g:true r:?theOrigWindRect]!;
  1340.     
  1341.                 size [window t:title o:specifier g:true ] r:{ x, y };                #To size the window
  1342.     
  1343.                 match [window t:title o:specifier g:true r:?theWindRect]!;
  1344.                 x := theWindRect[3] - theOrigWindRect[3];
  1345.                 y := theWindRect[4] - theOrigWindRect[4];
  1346.             end;
  1347.             else begin
  1348.                 size [window t:title o:specifier g:true] r:{ x, y };                        #To size the window
  1349.                 match [window t:title o:specifier g:true r:?theWindRect]!;
  1350.                 x := theWindRect[3] - x;
  1351.                 y := theWindRect[4] - y;
  1352.             end;
  1353.             str := "Resized window '{title}' relative {x} pixels wide and {y} pixels high";
  1354.         end;
  1355.         LogStr(str);
  1356.         noErrorFlag := 1;
  1357.     end;
  1358.     else
  1359.         LogStr("!@#$% Couldn't size window");
  1360.     return(noErrorFlag);    
  1361. end;  # SizeWindow()
  1362.  
  1363.  
  1364. #########################################################################
  1365. #                            ZoomWindow(specifier)
  1366. #========================================================================
  1367. # Author:        KTA
  1368. # Description:    Selects the zoom box on the requested window.  If no
  1369. #                parameters are passed, then the default behavior will
  1370. #                zoom the first window with a zoom box.
  1371. # Parameters:    specifier -    holds title or ordinality of window to zoom
  1372. # Returns:        0 - Couldn't zoom the window
  1373. #                1 - Zoomed the window OK
  1374. #========================================================================
  1375. # History:
  1376. #    KTA        3/8/90        Created
  1377. #    NJV        4/7/90        Changed name to ZoomWindow and added title parameter
  1378. #                        to zoom a window by title instead of ordinality 1
  1379. #    NJV        4/9/90        Changed title parameter to byOrdinality and specifier
  1380. #                        to allow window specification by title or ordinality.
  1381. #    NJV        5/13/90        Condensed parameters to a single parameter
  1382. #                        Took out select window call
  1383. #    DM        9/27/90        Optimized and added FindWindow
  1384. #                        Changed specifier default to 0 so it will match the 
  1385. #                        first document window.
  1386. #    NJV        6/25/91        Added check to assure zoom box is on screen
  1387. #    DM/KA    9/30/91        Let FindWindow() handle errors
  1388. #    J Marsh    1/2/92        Fixed zoom-box-on-screen check for multiple monitors
  1389. #    ML        4/21/92        Added parens around PtInRect(theHitPoint,item.r) in
  1390. #                        if statement for compatibility with VU 2.0d3
  1391. #########################################################################
  1392. task ZoomWindow(specifier:= 0) begin
  1393.     noErrorFlag := 0;            # Init error condition
  1394.     theWind := FindWindow(specifier);
  1395.     if theWind begin
  1396.         windOrd := theWind.o;
  1397.         title := theWind.t;
  1398.         zoomBox := theWind.z;
  1399.         theRect := theWind.r;                        # njv - added 6/25/91
  1400.         theHitPoint := {theRect[3]-20,theRect[2]};    # hit point for zoom box
  1401.         hitPointOffScreen := true;
  1402.         
  1403.         if (specifier > 0)
  1404.             Str1 := "of ordinality {specifier} ";
  1405.         else if (specifier = 0)
  1406.             Str1 := "with a zoom box ";
  1407.         else if( not IsNumber(specifier))
  1408.             Str1 := "";
  1409.         if (zoomBox) begin
  1410.             # test to see if zoom box is on screen
  1411.             screenList := collect [screen]!;
  1412.             for each item in screenList begin
  1413.                 if (PtInRect(theHitPoint,item.r))     # see if zoom box on screen
  1414.                     hitPointOffScreen := false;
  1415.             end;
  1416.             if (hitPointOffScreen)    # can't zoom window
  1417.                 str := "Couldn't zoom window {Str1}titled '{title}' - zoom box off screen";
  1418.             else begin                # zoom the window
  1419.                 zoom [window o:windOrd t:title]!;    #To zoom the window
  1420.                 str := "Zoomed window {Str1}titled '{title}'";
  1421.             end;
  1422.         end;
  1423.         else begin
  1424.             str := "No zoom box found in window {Str1}titled '{title}'";
  1425.         end;
  1426.         LogStr(str);
  1427.         noErrorFlag := 1;            # Init error condition
  1428.     end; 
  1429.     else 
  1430.         LogStr("!@#$% Couldn't zoom window");
  1431.  
  1432.     return(noErrorFlag);
  1433. end;  # ZoomWindow()
  1434.  
  1435.  
  1436. ########################################################################
  1437. #                            ScrollWindow(foo,x,y)
  1438. #=======================================================================
  1439. # Author:        KTA/NJV
  1440. # Description:    This routine will scroll the specified scrollbar on
  1441. #                the active window.
  1442. # Parameters:    foo = 'H' - for horizontal scrollbar
  1443. #                    = 'V' - for vertical scrollbar
  1444. #                <x><y> = the fraction x/y
  1445. # Returns:        0 - Couldn't scroll the scroll bar
  1446. #                1 - Scrolled the scroll bar
  1447. # Examples:        ScrollWindow('H',1,2)  will scroll the horizontal bar 1/2
  1448. # Assumptions:    That the scrollbars are present. This routine collects
  1449. #                only the first two scroll bars, which are assumed to be 
  1450. #                the horizontal and vertical scroll bars. 
  1451. #                This routine is not 100% reliable.
  1452. #=======================================================================
  1453. # History:
  1454. #     KTA/NJV    11/21/89    Created
  1455. #    KTA        1/20/89        Added Scrapbook Support
  1456. #    KTA        1/20/90        Added LogStr call
  1457. #    KTA     5/14/90        Removed scrapbook Support
  1458. #                        Now checks to see if scrolllbars are enabled
  1459. #    NJV        6/25/90        Added random scrolling
  1460. #    NJV        7/5/90        Added GetVHScrollBars call.
  1461. #    NJV        6/25/91        Changed check for enabled.
  1462. #########################################################################
  1463. task ScrollWindow(foo,x:=-1,y:=-1) begin
  1464.     theScrollBars := GetVHScrollBars();
  1465.     if (not theScrollBars)
  1466.         return(0);        # error - couldn't find scroll bars
  1467.     vertical := theScrollBars[1];
  1468.     verticalDiff := vertical.s;
  1469.     horizontal := theScrollBars[2];
  1470.     horizontalDiff := horizontal.s;
  1471.  
  1472.     if (foo = 'V') or (foo = 'v') begin
  1473.         if (x=-1) or (y=-1) begin    # generate random value
  1474.             x := random(0,verticalDiff[2]);
  1475.             y := verticalDiff[2];
  1476.         end;
  1477.         if (vertical.e) begin        #Test to see if Scrollbars are enabled
  1478.             scroll vertical a:{x,y};
  1479.             LogStr("Scrolled the vertical scroll bar Absolute ({x}, {y})");
  1480.         end;
  1481.         else begin
  1482.              LogStr("!@#$% The vertical scroll bar was not enabled to scroll");
  1483.             return(0);
  1484.         end;
  1485.     end;
  1486.     else begin
  1487.         if (x=-1) or (y=-1) begin    # generate random value
  1488.             x := random(0,horizontalDiff[2]);
  1489.             y := horizontalDiff[2];
  1490.         end;
  1491.         if (horizontal.e) begin        #Test to see if Scrollbars are enabled
  1492.             scroll horizontal a:{x,y};
  1493.             LogStr("Scrolled the horizontal scroll bar absolute ({x}, {y})");
  1494.         end;
  1495.         else begin
  1496.             LogStr("!@#$% The horizontal scroll bar was not enabled to scroll");
  1497.             return(0);
  1498.         end;
  1499.     end;
  1500.     return(1);
  1501. end;  # ScrollWindow()
  1502.  
  1503. ########################################################################
  1504. #                            GetVHScrollBars()
  1505. #=======================================================================
  1506. # Author:            NJV
  1507. # Description:        This routine will return the vertical and horizontal
  1508. #                    scroll bars.
  1509. # Parameters:        None
  1510. # Returns:            0 - Couldn't find scroll bars
  1511. #                    {vertical,horizontal} - list of vertical and horizontal
  1512. #                                            scroll bars
  1513. # Examples:            scrollBars := GetVHScrollBars();
  1514. # Assumptions:        Top of vertical scroll bar is at a lower vertical value
  1515. #                    that the horizontal (i.e. the top of vertical rect is smaller
  1516. #                    than the top of the horizontal scroll bar's rect).
  1517. #=======================================================================
  1518. # History:
  1519. #    NJV        6/25/90        Created
  1520. #########################################################################
  1521. task GetVHScrollBars() begin
  1522.     ScrollWindowlist :=collect[scrollbar];
  1523.     if not (card(ScrollWindowlist)) begin
  1524.         LogStr("!@#$% There were no recognizable scroll bars present");
  1525.         return(0);
  1526.     end;
  1527.     Rec1 := ScrollWindowlist[1];
  1528.     Rec2 := ScrollWindowlist[2];
  1529.     Rec1R := Rec1.r[1];
  1530.     Rec2R := Rec2.r[1];
  1531.  
  1532.     if (Rec1R < Rec2R) begin         #To determine which scroll bar is Vertical/Horizontal
  1533.         horizontal := Rec1;
  1534.         vertical := Rec2;
  1535.     end;
  1536.     else begin
  1537.         horizontal := Rec2;
  1538.         vertical := Rec1;
  1539.     end;
  1540.     return({vertical,horizontal});
  1541. end;
  1542.  
  1543. #########################################################################
  1544. #                CloseWindow(howClose, overwrite, specifier,DocName)
  1545. #========================================================================
  1546. # Author:        KTA/NJV/DMM
  1547. # Description:    This routine will close the specified window.  If no
  1548. #                parameters are passed to this routine, the default behavior
  1549. #                will select the close box of the first window with a close box.
  1550. # Parameters:    howClose -    0 -    tries all three ways noted below to close the
  1551. #                                window (if needed)
  1552. #                            1 -    tries to close window by selecting "Close" menu
  1553. #                                item
  1554. #                            2 -    tries to close window by typing "Close" menu
  1555. #                                item's key equivalent
  1556. #                            3 -    tries to close window by selecting window's
  1557. #                                close box
  1558. #                overwrite -    0 -    will select "No" from a save-changes dialog
  1559. #                                if one appears when closing window
  1560. #                            1 -    will select "Yes" to save changes
  1561. #                specifier -    holds title or ordinality of window to close
  1562. #                DocName -    string holding new document name - if overWrite
  1563. #                            parameter is 1, then DocName will be used for
  1564. #                            naming the file.
  1565. # Returns:        1 - Closed window OK
  1566. #                0 - Couldn't find window to close
  1567. #========================================================================
  1568. # History:
  1569. #    KTA/DM    1/20/90        Created
  1570. #    NJV        4/07/90        Changed name from CloseW() and added title parameter
  1571. #    NJV        4/27/90        Changed to call closeOneWindow and added parameters
  1572. #    NJV        5/13/90        Condensed parameters and added CloseOneWindow in-line
  1573. #    KTA/NJV 7/17/90        Added DocName parameter, updated checkYesNo calls
  1574. #    KTA        8/21/90        Fixed bug in closing by specifier-used to close front window
  1575. #    DM        9/24/90        Fixed error meesage for "No window" case.  Commented out 
  1576. #                        extra(?) match window
  1577. #    DM        9/27/90        Optimized and added FindWindow
  1578. #                        Changed specifier default to 0 so it will match the 
  1579. #                        first document window.
  1580. #    ECH        11/5/90        in howClose 3, closed window using ord and theTitle instead
  1581. #                        of just theTitle in case two windows have the same name
  1582. #    NJV        11/27/90    Added documentation for DocName
  1583. #    KTA/DM    9/30/91        Rewrote - check to see if window is still open
  1584. #    J Marsh    1/29/92        Reset theTitle after dirty save to eliminate bogus error
  1585. #
  1586. ###########################################################################
  1587. task CloseWindow(howClose := 3,saveFlag := 1,specifier := 0,newDocName :="") begin
  1588.     noErrorFlag := 0;
  1589.  
  1590.     theWind := FindWindow(specifier);    # Find the specified window
  1591.     
  1592.     if (theWind) begin                    # IF - we found the window
  1593.         ord := theWind.o;                # make assignments
  1594.         theTitle := theWind.t;
  1595.         if (ord <> 1)
  1596.         begin
  1597.             SelectWindow(ord);        # Select the window if it's not the frontmost
  1598.             theWind := FindWindow(theTitle);    
  1599.             ord := theWind.o;        # Reassign Ord because selection may have changed ordinality
  1600.         end;
  1601.         if (not howClose)            # Try all methods until one works
  1602.             howClose := {1,2,3};
  1603.         else
  1604.             howClose := {howClose};    # Just use the specified method
  1605.             
  1606.         numItems := Card(howClose);
  1607.         for i := 1 to numItems        # Execute once if way to close is specified 
  1608.         begin                        # otherwise three times attempting all methods
  1609.             closeMethod := howClose[i];
  1610.             if (closeMethod = 1) begin        # Close with menu item
  1611.                 if(SelectMenuItem("Close","File"))
  1612.                     noErrorFlag := 1;        # Success
  1613.             end;
  1614.             if (closeMethod = 2) begin        # Close with key equivelant
  1615.                 closeKey := match[menuItem t:"Close"];
  1616.                 if (closeKey.k) begin
  1617.                     KeyEq(closeKey.k);
  1618.                     noErrorFlag := 1;        # Success
  1619.                 end;
  1620.             end;
  1621.                 
  1622.             if (closeMethod = 3) begin        # Close with close box
  1623.                 if (theWind.c)
  1624.                 begin
  1625.                     close [window o:ord t:theTitle c:true]!;
  1626.                     LogStr("Selected the close box on window titled '{theTitle}'");
  1627.                     noErrorFlag := 1;        # Success
  1628.                 end;
  1629.                 else
  1630.                     LogStr("Couldn't find the close box on window titled '{theTitle}'");
  1631.             end;
  1632.     
  1633.             if (noErrorFlag)             # IF - we had a success        
  1634.                 i := numItems;            # break because window should be closed
  1635.         end;
  1636.  
  1637.         if (noErrorFlag)                  # IF - we had a success    
  1638.         begin
  1639.             if(checkYesNo(saveFlag))    # Check if a 'Save Document??' dialog appeared
  1640.                 if(saveFlag)            # if the dialog appeared and we want to save 
  1641.                     if (match[button t:"DeskTop"]!)        # check for Standard File
  1642.                         begin
  1643.                             NameOk(newDocName,true);
  1644.                             theTitle := global lastSavedFile;
  1645.                         end;
  1646.         end;
  1647.  
  1648.         temp := global LogLevel;        # We want our own logging
  1649.         LogLevel := 0;
  1650.     
  1651.         if(FindWindow(theTitle))         # Is the window we just closed still open
  1652.         begin
  1653.             LogLevel := temp;            # Reset logging
  1654.             LogStr("!@#$% Sorry, the window - {theTitle} is still open");
  1655.             noErrorFlag := 0;
  1656.         end;
  1657.         else
  1658.             LogLevel := temp;            # Reset logging
  1659.     end;
  1660.     return(noErrorFlag);                # Return Result
  1661. end; # CloseWindow()
  1662.  
  1663. #########################################################################
  1664. #             MoveRelativeToWindow(x, y, specifier,mouseDown,inset)
  1665. #========================================================================
  1666. # Author:        NJV
  1667. # Description:    This routine will calculate the window's rectangle
  1668. #                and add x and y input parameters to the 
  1669. #                rectangle's top-left coordinate point.  It will then
  1670. #                move the mouse to that location.  The window is
  1671. #                specified by the specifier input parameter.  If the
  1672. #                specifier parameter is not present, the default
  1673. #                behavior will move relative to the frontmost window.
  1674. # Parameters:    x - int representing left (x) coord 
  1675. #                    or List of points.
  1676. #                y - int representing top (y) coord
  1677. #                specifier - holds title or ordinality of window
  1678. #                            0 matches first s:document c:true g:true window
  1679. #                mouseDown - 0 - don't hold mouse key down while moving
  1680. #                            1 - press mouse key down - move - release
  1681. #                            2 - Click after moving - no mouse down during move
  1682. #                x is ptList    3 - MultiDrag (pressmouse - move - move - move - release)
  1683. #                            4 - move - release
  1684. #                x is ptList    5 - MultiClick (click - move - click - move - click)
  1685. #                inset    -   inset from window rect for GetXYRandom
  1686. # Returns:        Nothing
  1687. # Examples:        MoveRelativeToWindow(12,25);
  1688. # Assumptions:    Assumes there is a window on the screen 
  1689. #========================================================================
  1690. # History:
  1691. #     NJV        10/2/89        Created
  1692. #    NJV        5/13/90        Changed thePoint parameter to two parameters (x, y)
  1693. #    NJV        5/22/90        Added specifier parameter
  1694. #    NJV        7/5/90        Added mouseDown and mouseUp parameters for MoveMouse
  1695. #    NJV        7/9/90        Added matchTarget parameter for diabling target matching
  1696. #    KTA        7/17/90        Added MouseDown = 2 - click after move
  1697. #    NJV        7/17/90        Took out matchTarget and mouseUp parameters
  1698. #    DM        9/24/90        Added inset param so it can be passed to GetXYRandom.
  1699. #                        Added 0 option for specifier so it will match the 
  1700. #                        first document window.
  1701. #    DM        9/27/90        Optimized and added FindWindow
  1702. #    KTA        9/22/91        Added final logStr() - it was missing
  1703. #    DM/KA    9/30/91        Let FindWindow() handle errors
  1704. #    KA        4/21/92        Handle PointLists
  1705. #########################################################################
  1706. task MoveRelativeToWindow(x:= 'random', y:= 'random', specifier:=0,mouseDown:=0,inset:= {30,30,30,30}) begin
  1707.     returnVal := 0;                # Init error condition
  1708.     if ( x='random') begin    # user wants random mouse move
  1709.         xyRandom := GetXYRandom(inset, specifier);
  1710.         x := xyRandom[1];
  1711.         y := xyRandom[2];
  1712.         returnVal := xyRandom;
  1713.     end;
  1714.     theWind := FindWindow(specifier);
  1715.     if theWind 
  1716.     begin
  1717.         lvWindRect := theWind.r;
  1718.         lvX := lvWindRect[1];            # X = LEFT (the X co-ord)
  1719.         lvY := lvWindRect[2];
  1720.  
  1721.         # Handle PointList
  1722.         if (typeOF(x) = "list")            # Need to move to a list of coordinates
  1723.         begin
  1724.             MoveMouse(x,{lvX,lvY},1,mouseDown);    # move to the calculated location
  1725.             returnVal := {lvX,lvY};
  1726.         end;
  1727.         else
  1728.         begin
  1729.             lvFinalLeft := x + lvX;            # calculate absolutely X
  1730.             lvFinalTop := y + lvY;            # calculate absolutely Y
  1731.             MoveMouse(lvFinalLeft,lvFinalTop,1,mouseDown);    # move to the calculated location
  1732.             returnVal := {lvFinalLeft,lvFinalTop};
  1733.         end;
  1734.     end;
  1735.     return (returnVal);
  1736. end; # MoveRelativeToWindow()
  1737.  
  1738.  
  1739. #########################################################################
  1740. #                 MoveMouse(x, y, absolutely, mouseDown)
  1741. #========================================================================
  1742. # Author:        DMM
  1743. # Description:    This routine will move the mouse x,y relative to
  1744. #                it s current location  If x and y are absent or
  1745. #                equal to "random", a random move is generated.
  1746. # Parameters:    absolutely - 1 if move absolutely, 0 if relative
  1747. #                x         x distance to move mouse
  1748. #                y         y distance to move mouse
  1749. #                        if x and y are absent or := "random" then a 
  1750. #                        random move is generated
  1751. #                absolutely    -    1 to move to absolute location
  1752. #                                0 to move relative to current location
  1753. #                mouseDown - 0 - don't hold mouse key down while moving
  1754. #                            1 - press mouse key down - move - release
  1755. #                            2 - Click after moving - no mouse down during move
  1756. #                            3 - press mouse key down - move - don't release
  1757. #                x is List    3 - MultiDrag
  1758. #                            4 - move - release
  1759. #                x is List    5 - MultiClick
  1760. # Returns:        Nothing
  1761. #========================================================================
  1762. # History:
  1763. #    DM        4/19/90        Created
  1764. #    NJV        4/26/90        Changed to allow for relative or absolutely moving
  1765. #    NJV        5/13/90        Re-ordered parameters
  1766. #    NJV        7/5/90        Added mouseUp parameter (defaults to original behavior)
  1767. #    NJV        7/5/90        Changed 2 LogStr calls to 1.
  1768. #    NJV        7/9/90        Added matchTarget parameter (LogStr disables target if mouseDown)
  1769. #    KTA        7/17/90        Added MouseDown = 2 - click after move
  1770. #    NJV        7/17/90        Took out matchTarget parameter - used mouseDown and mouseUp
  1771. #    NJV        7/17/90        Took out mouseUp parameter - changed possible values for mouseDown
  1772. #    KTA        4/21/92        Handle pointList
  1773. #########################################################################
  1774. task MoveMouse(x := 'random', y := 'random', absolutely := 1, mouseDown := 0)
  1775. begin
  1776.     if ( x='random') begin    # user wants random mouse move
  1777.         xyRandom := getXYRandom();
  1778.         x := xyRandom[1];
  1779.         y := xyRandom[2];
  1780.     end;
  1781.     
  1782.     if ((mouseDown = 1) or (mouseDown = 3))
  1783.         PressMouse;
  1784.     
  1785.     #### To Handle PointLists  #####
  1786.     if (typeOF(x) = "list")            # Need to move to a list of coordinates
  1787.     begin
  1788.         pointList := x;
  1789.         xOffSet := 0;
  1790.         yOffSet := 0;
  1791.         if (typeOF(y) = "list")                # If its relative to window
  1792.         begin                                # We pass in y as the offset of the window
  1793.             xOffSet := y[1];
  1794.             yOffSet := y[2];
  1795.         end;
  1796.         if (mouseDown = 5)                # To start the multiClick
  1797.             click;
  1798.  
  1799.         for each pairPoints in pointList
  1800.         begin
  1801.             nuX := pairPoints[1];
  1802.             nuY := pairPoints[2];
  1803.             x := nuX + xOffSet;            # If relative to window offset
  1804.             y := nuY + yOffSet;            # otherwise the offset is 0
  1805.             if (absolutely)
  1806.                 move a: { x, y };
  1807.             else
  1808.                 move r: { x, y };
  1809.                 
  1810.             if (mouseDown = 5)        # Click for Multiclick
  1811.                 click;
  1812.         end;
  1813.         if (mouseDown = 3)            # Finished MultiDrag
  1814.             releaseMouse;
  1815.     end;
  1816.     else
  1817.     begin
  1818.         if (absolutely) begin
  1819.             move a: { x, y };
  1820.             str := "Moved the mouse to absolute location ∂({x},{y}∂)";
  1821.         end;
  1822.         else begin
  1823.             move r: { x, y };
  1824.             str := "Moved the mouse relative ∂({x},{y}∂) to previous position";
  1825.         end;
  1826.         
  1827.         # release mouse if needed
  1828.         if ((mouseDown = 1) or (mouseDown = 4))
  1829.             ReleaseMouse;
  1830.     
  1831.         # add mouse down to log string if needed
  1832.         if ((mouseDown = 1) or (mouseDown = 3) or (mouseDown = 4))
  1833.             str := "{str} with mouse button held down";
  1834.         
  1835.         # click if needed
  1836.         if (mouseDown = 2 ) begin
  1837.             Click;
  1838.             str := "{str} and clicked";
  1839.         end;
  1840.         
  1841.         # log it
  1842.         LogStr(str);
  1843.     end;
  1844. end; # MoveMouse()
  1845.  
  1846. ########################################################################
  1847. #                        GetXYRandom(inset, specifier)
  1848. #=======================================================================
  1849. # Author:             SL
  1850. # Description:        Returns a random X and Y coordinate in the specified
  1851. #                    screen or window.
  1852. # Parameters:        inset - ltrb inset from scrn or window
  1853. #                    specifier > 0 window to find coords in
  1854. #                              = O coords in window with s:doc g:true and c:true
  1855. #                              < 0 coords in specified screen.  Screen numbersta
  1856. #                                is negative of specifier.
  1857. # Returns:            xyRandom - List of random X and Y.  eg. { x, y }
  1858. #=======================================================================
  1859. # History:
  1860. #    SL        4/5/90        Created
  1861. #    NJV        5/13/90        Added scrn parameter
  1862. #    DM        9/23/90        Added option to get random points in front window
  1863. #    DM        9/23/90        Changed so the default is random coords in windows
  1864. #                        rather than screen coords.  
  1865. #    DM        10/9/91        Let FindWindow handle screens and match failures
  1866. #                        Set the default for inset to the global gInset
  1867. #    KTA        4/21/92        Added return of PointList
  1868. ########################################################################
  1869. Task GetXYRandom(inset := { 0,20,20,20}, specifier := 0, numPts := 1) 
  1870. begin        
  1871.     theDesc := FindWindow(specifier);
  1872.     pointlist := {};
  1873.     if(theDesc) begin
  1874.         rect := theDesc.r;
  1875.         if (rect) 
  1876.         begin
  1877.             maxX := rect[3] - rect[1] - inset[3];
  1878.             maxY := rect[4] - rect[2] - inset[4];
  1879.             for i := 1 to numPts
  1880.             begin
  1881.                 xRandom := random(inset[1], maxX);
  1882.                 yRandom := random(inset[2], maxY);
  1883.                 
  1884.                 thePoint := { xRandom, yRandom };
  1885.                 if(numPts > 1)        # Do we want a point list
  1886.                     pointList := insert(thePoint , i, pointList );
  1887.             end;
  1888.             if(numPts = 1)    # If there is only one return it just like we always have
  1889.                 returnVal := thePoint;
  1890.             else             # Otherwise return a list of points { {xPt,yPt},{xPt2, yPt2} };
  1891.                 returnVal := pointList;
  1892.         end;
  1893.         else
  1894.             returnVal := 0;
  1895.     end;
  1896.     else
  1897.         returnVal := 0;
  1898.     return(returnVal);
  1899. end; # getXYRandom()
  1900.  
  1901. #########################################################################
  1902. #                        NameOK(NameDoc, replaceFlag)
  1903. #========================================================================
  1904. # Author:        KTA
  1905. # Description:    This routine will type a name (NameDoc) into the text edit
  1906. #                field.  Then it will press the ReturnKey. If there is a
  1907. #                document already named <NameDoc> then this task will check
  1908. #                the replaceFlag.  If it is defined as anything but true
  1909. #                it will select NO to 'Replace Existing?' dialog. It will
  1910. #                then type the time (based on a 24 hour clock) after the
  1911. #                name and retype the ReturnKey. The Default is to replace
  1912. #                an existing document with the same name. It will also call
  1913. #                getNewFileName to create a file name if one is not provided.
  1914. # Parameters:    NameDoc - string holding the name to name the document
  1915. #                replaceFlag - 0 to select 'No' to 'Replace Existing' dialog
  1916. #                              1 to select 'Yes' to replace exisiting file.
  1917. # Returns:        string - filename of saved document
  1918. # Examples:        NameOk('Untitled1'); to name the file 'Untitled1'
  1919. # Assumptions:    That the SF_Put dialog is present
  1920. #                 A call to SelectMenuItem('Save As', 'File'); should probably
  1921. #                be made prior to calling NameOK()
  1922. #========================================================================
  1923. # History:
  1924. #     KTA        11/20/89    Created
  1925. #    KTA     5/17/90        Added Global LastSavedFile;
  1926. #    KTA     6/1/90        Fixed so that the time will be appended in 7.0
  1927. #    NJV        6/26/90        Returns filename
  1928. #    KTA     7/13/90     Remove Return 0 if no 'Yes' Button
  1929. #    NJV        7/27/90        Will keep renaming until original filename
  1930. #    KTA        8/2/90        Matches for a dialog
  1931. #    KTA        8/22/90        DisableAllLogging after matching for dialog once.
  1932. #    NJV        11/27/90    Updated documentation for replaceflag.
  1933. #    KTA        12/20/90    Updated for  7.0ß2+ - changes to dialog 
  1934. #    KTA        2/25/91        Better check for SF Dialog
  1935. #    KTA        7/10/91        Totally rewrote using SF_Navigate
  1936. #    KTA        7/22/91        Check for replace dialog (VU bug) fix
  1937. #    KTA        4/14/92        Added 6.0x support
  1938. #########################################################################
  1939. Task NameOK(NameDoc := "", replaceFlag := true, SelectSaveAs := False, Pathlist := global SF_PUTLocation) 
  1940. begin
  1941.     global IsSys7;
  1942.     returnVal := 0;
  1943.     
  1944.     if (SelectSaveAs)
  1945.         selectmenuItem("Save As", "File");            # Select the Open MenuItem
  1946.  
  1947.     wait(2);
  1948.     ## Check to see if Standard File is present
  1949.     SF_Dialog := match[window o:1 s:dialog c:false z:false g:false]!;
  1950.     if (SF_Dialog ) 
  1951.     begin
  1952.         println;
  1953.         println "############## Standard File - Save  ##############";
  1954.         if (NameDoc = "") 
  1955.             nameDoc := GetNewFileName();    #To get a name    
  1956.     
  1957.         if (PathList) and (IsSys7)      # No navigating in 6.0
  1958.             SF_Navigate( PathList ,1);
  1959.     
  1960.         TypeStr(NameDoc);        # Type the name of the Document
  1961.         SpecialKey(ReturnKey, 'Return Key');    # Accept the SF dialog
  1962.         
  1963.         ## 7.0 and 6.0 have different 'Replace Existing' dialogs
  1964.         ## Determine if Replace Existing Dialog is present
  1965.         ReplaceExisting := collect[button w:[window o:1]];        
  1966.         if (Card(ReplaceExisting) = 2)
  1967.             NameDoc := ReplaceExist(replaceFlag, NameDoc);
  1968.         else 
  1969.             DialogCheck("",'Ok');    # Look for other problems 
  1970.             
  1971.         global LastSavedFile := NameDoc;
  1972.         LogStr( "The document's name is - '{NameDoc}'");
  1973.         returnVal := 1;
  1974.     end;
  1975.     else 
  1976.         LogStr( "!@#$% The Standard_File dialog is not present");
  1977.  
  1978.     return(returnVal);
  1979. end; # NameOK()
  1980.  
  1981. #########################################################################
  1982. #                        OpenDoc(namedoc,SelectOpen)
  1983. #========================================================================
  1984. # Author:        KTA
  1985. # Description:    This routine will select 'Open' from the 'File' menu, type
  1986. #                the string held in the nameDoc parameter, and
  1987. #                then press the returnkey.  It will check to see that
  1988. #                the frontmost window's title contains namedoc.  If not,
  1989. #                it assumes that the wrong file opened.  It will not select
  1990. #                'Open' if the SelectOpen parameter is 0.
  1991. # Parameters:    namedoc - string name of document to open
  1992. #                SelectOpen - 0 to disable selecting of the 'Open' menu item.
  1993. #                             1 to select 'Open' from the 'File' menu
  1994. #                             2 keyEq - 'o'
  1995. # Returns:        1 - Document opened OK
  1996. #                0 - Document not opened OK
  1997. # Assumptions:    Works with SF_Get, but don't have NameDoc be to long
  1998. #                of a string.
  1999. # Examples:        OpenDoc('Untit'); will select a document such as 'Untitled'.
  2000. #========================================================================
  2001. # History:
  2002. #    KTA        3/16/90        Created
  2003. #    KTA        4/25/90        Changed SelectMenuItem to support by name
  2004. #    NJV        6/26/90        Checks to see if window opened is desired window
  2005. #                        Added return values
  2006. #    DMM        6/28/90        Accounted for no window open
  2007. #    KTA        9/4/90        Added SelectOpen 
  2008. #    NJV        11/27/90    Updated documentation for SelectOpen.
  2009. #    KTA        7/10/91        Rewrote with SF_Navigate
  2010. #    KTA        4/15/92        Reimplemented 6.0x support
  2011. #    KTA        4/16/92        Check to verify SF is no longer present
  2012. #    KTA        4/21/92        (SelectOpen = 2) - keyEq('o');
  2013. #########################################################################
  2014. Task OpenDoc(namedoc := "", SelectOpen :=1, pathlist :={}) 
  2015. begin    
  2016.     global LastSavedFile, IsSys7;
  2017.     returnVal := 0;
  2018.     if(namedoc)
  2019.     begin
  2020.         if (SelectOpen = 1) 
  2021.             selectmenuItem("Open", "File");    # Select the Open menuItem
  2022.         else if (SelectOpen = 2) 
  2023.             KeyEq('o');                        # Keyboard equivelant 'o' for open
  2024.             
  2025.         wait(2);
  2026.         SF_Dialog := match[window o:1 s:dialog c:false z:false g:false]!;
  2027.         if (SF_Dialog ) 
  2028.         begin
  2029.             println;
  2030.             println "############## Standard File - Open  ##############";
  2031.             if ( PathList ) and (IsSys7)    # No navigating in 6.0
  2032.                 SF_Navigate( PathList );
  2033.             
  2034.             TypeStr(NameDoc);                # Type the name of the file to open
  2035.             SpecialKey(ReturnKey, 'Return Key');    # Accept the dialog
  2036.             Wait(2);
  2037.             
  2038.             #### Check to make sure Standard file is no longer present
  2039.             SF_Dialog := match[window o:1 s:dialog c:false z:false g:false]!;
  2040.             if (SF_Dialog ) 
  2041.             begin
  2042.                 LogStr("!@#$% Standard File is still present and it shouldn't be");
  2043.                 SpecialKey(escapeKey, "Escape Key");    # Exit (changed from 'cancel' button - intl)
  2044.                 returnVal := 0;            # Failure
  2045.             end;
  2046.             else
  2047.             begin
  2048.                 ### match the top document window (Hopefully the Document that was just opened)
  2049.                 RetrievedDoc := match[window g:true z:true t:?DocName]!;        # Match the document window
  2050.                 if not(RetrievedDoc)
  2051.                     LogStr("!@#$% No open window with grow and zoom boxes");
  2052.                 else
  2053.                     LogStr("The front document is named '{DocName}'");
  2054.                 
  2055.                 ## Is the document the one we expected
  2056.                 if (isSubString(namedoc,DocName))        # looks like the right file
  2057.                     returnVal := 1;                        # return O'TAY BUCKWHEAT
  2058.                 else
  2059.                     LogStr("!@#$% It appears that the wrong file was opened, BuckWheat"); 
  2060.             end;
  2061.         end;
  2062.         else 
  2063.             LogStr( "!@#$% The Standard_File dialog is not present");
  2064.     end;
  2065.     else
  2066.         LogStr("!@#$% No file name was specified");
  2067.  
  2068.     return(returnVal);
  2069. end;  # OpenDoc()
  2070.  
  2071. #########################################################################
  2072. #            SF_Navigate(PathList, TEToggle, FinalReturn)    
  2073. #========================================================================
  2074. # Author:        KTA
  2075. # Description:    Controls the navigation in Standard File. 
  2076. #                Assigns a global SF_OriginalPath to the current directory 
  2077. #                for return navigation.
  2078. #                Passes all parameters to SF_Type which performs actual navigation.
  2079. # Parameters:    PathList := List of directories beginning with the disk name.
  2080. #                TEToggle := Whether toggling from a text edit field is required 
  2081. #                            to navigate.
  2082. #                            1 - Toggle
  2083. #                            0 - No toggling required
  2084. #                FinalReturn := Whether to accept the final item in <Pathlist>
  2085. # Returns:        Pathlist
  2086. #========================================================================
  2087. # History:
  2088. #    KTA        7/3/91        Created
  2089. #    KTA        Don't build SF_OriginalPath unless navigation is required 
  2090. #########################################################################
  2091. task SF_Navigate( PathList :={},TEToggle :=0, FinalReturn := 1) 
  2092. begin
  2093.     # Verify that Standard File is present
  2094.     SF_Dialog := match[window o:1 s:dialog c:false z:false g:false]!;
  2095.     if (SF_Dialog ) 
  2096.     begin
  2097.         if (Pathlist)    # Path list needs to be specified
  2098.         begin        
  2099.             OrigPathList :={};                        # Initialize variable    
  2100.             match[popup i:?Popupitems];                # match SF popup 
  2101.             
  2102.             for x := 1 to (card PopUpItems-1)        # Build a Pathlist 
  2103.                 OrigPathList := insert(PopUpItems[x].t,1,OrigPathList);
  2104.     
  2105.             if (OrigPathList = Pathlist)            # Is the current directory the desired directory
  2106.                 Pathlist := {};
  2107.             else if (TypeOf(PathList) = "integer")     # return to where you started
  2108.             begin
  2109.                 if (PathList = 1)     
  2110.                     PathList := Global SF_OriginalPath;
  2111.             end;
  2112.             else                                     # Update the gobal SF_OriginalPath
  2113.                 SF_OriginalPath := OrigPathList;
  2114.             
  2115.             SFPath := '';
  2116.             For each item in PathList                 # For logging purposes - build pathlist
  2117.                 SFPath := SFPath + Item + ":";
  2118.             LogStr( "Standard File Navigation to the path - ∂[{SFPath}∂]",3);
  2119.             
  2120.              SF_Type(PathList,TEToggle, FinalReturn);
  2121.             Return(pathlist);
  2122.         end;
  2123.         else
  2124.             LogStr( "Standard File is set to current default directory",3);
  2125.     end;
  2126.     else
  2127.     begin
  2128.         LogStr( "!@#$% The Standard_File dialog is not present");
  2129.         return(0);
  2130.     end;
  2131. end; # SF_Navigate()
  2132.  
  2133. #########################################################################
  2134. #                            SF_Type(PathList, TEToggle, FinalReturn )    
  2135. #========================================================================
  2136. # Author:        KTA
  2137. # Description:    Performs navigation in Standard File.
  2138. #                Selects the 'DeskTop' button. Then types each item in <PathList>
  2139. #                folled by a returnKey.
  2140. # Parameters:    PathList := List of directories beginning with the disk name.
  2141. #                TEToggle := Whether toggling from a text edit field is required 
  2142. #                            to navigate.
  2143. #                            1 - Toggle
  2144. #                            0 - No toggling required
  2145. #                FinalReturn := Whether to accept the final item in <Pathlist>
  2146. # Returns:        Nada
  2147. #========================================================================
  2148. # History:
  2149. #    KTA        7/3/91        Created
  2150. #########################################################################
  2151. task SF_Type(PathList,TEToggle :=0, FinalReturn := 1) begin
  2152.     SelectButton('Desktop');    # Start from top
  2153.     if (TEToggle)
  2154.         type k:{TabKey};        # Makes directory list active
  2155.     wait(2);
  2156.     TypeList(PathList,1,FinalReturn);    # Actual navigation
  2157.     if (TEToggle)
  2158.         type k:{TabKey};        # Makes text edit  active
  2159. end; # SF_Type()
  2160.  
  2161. #########################################################################
  2162. #            ReplaceExist( replaceFlag,NameDoc)    
  2163. #========================================================================
  2164. # Author:        KTA
  2165. # Description:    Handles the 'Replace existing?' dialog.
  2166. # Parameters:    ReplaceExist := Whether to Replace a document with the same name
  2167. #                or generate a unique name.
  2168. #                1 - Overwrite document with same name.
  2169. #                0 - Do not overwrite.  Generate unique name.
  2170. #                NameDoc := Name of file which already exists on disk.
  2171. # Returns:        NameDoc ( will be identical to the initial one if replaceFlag is set.
  2172. #========================================================================
  2173. # History:
  2174. #    KTA        6/30/91        Created
  2175. #    KTA        4/15/92        Updated to handle 6.0x and 7.0
  2176. #                        6.0 and 7.0 have different 'Repalce Existing' dialogs
  2177. #########################################################################
  2178. Task ReplaceExist( replaceFlag := true, NameDoc :='') 
  2179. begin
  2180.     println "    -- Replace Existing?? --";
  2181.     # Different button names on dialog
  2182.     if(global IsSys7)        # is System 7 or greater running
  2183.     begin
  2184.         ReplaceString := "Replace";
  2185.         CancelString := "Cancel";
  2186.     end;
  2187.     else            # Must be 6.0
  2188.     begin
  2189.         ReplaceString := "Yes";
  2190.         CancelString := "No";
  2191.     end;
  2192.  
  2193.     NewSuffix := "";
  2194.     if (replaceFlag)        # Want to replace
  2195.         SelectButton(ReplaceString);
  2196.     else 
  2197.     begin                    # Don't want to replace
  2198.         SelectButton(CancelString);
  2199.         TimeString := GetNewFileName(nameDoc);
  2200.         nameDoc := "{NameDoc}{TimeString}";
  2201.         if(IsSys7)        # 7.0 and 6.0 handle text entry differently in SF
  2202.             type k:{rightArrowKey};        # Places I beam after existing text in SF text edit
  2203.         TypeStr("{TimeString}");        # append time to NameDoc in 6.0/7.0
  2204.         SpecialKey(returnKey, 'Return key');
  2205.     end;
  2206.     return(NameDoc);
  2207. end; # ReplaceExist()
  2208.  
  2209. #########################################################################
  2210. #                            GetNewFileName(name)    
  2211. #========================================================================
  2212. # Author:        SL
  2213. # Description:    Gets a new file name by concatenating the app name and
  2214. #                the current time.
  2215. # Parameters:    name -    If this parameter is present, this routine will
  2216. #                        only pass back the time.  If this parameter is not
  2217. #                        present, then this routine will pass back a string
  2218. #                        consisting of the application name with the time
  2219. #                        appended to it.
  2220. # Returns:        newFileName - string name for new file name
  2221. #                    or just a time and Sec string
  2222. #========================================================================
  2223. # History:
  2224. #    SL        4/3/90        Created
  2225. #    KTA/DM    4/25/90     Reworked the whole thing
  2226. #    KTA        8/17/90        Added default parameter so wouldn't recieve error message
  2227. #    KTA        7/12/91        Now returns filename appended with Time and Sec.
  2228. #    KTA        4/15/92        If not System 7 will only return  Time and Sec.
  2229. #                         7.0 and 6.0 handle text entry differently in SF
  2230. #    KTA        4/15/92        Returns Time and Sec if includeNameFlag is not true
  2231. #########################################################################
  2232. Task GetNewFileName(name :="",includeNameFlag := 0) begin
  2233.     Global IsSys7;
  2234.     match [time h:?Tm s:?Sc];
  2235.     if (name)
  2236.     begin 
  2237.         if(includeNameFlag)
  2238.             newFileName := "{name} {Tm}{Sc}"; 
  2239.         else 
  2240.             newFileName := " {Tm}{Sc}"; 
  2241.     end;
  2242.     else 
  2243.     begin
  2244.         match [Application t:?appName];
  2245.         newFileName := "@{appName}-{Tm}{Sc}";
  2246.     end;
  2247.     return(newFileName);
  2248. end; # GetNewFileName()
  2249.  
  2250. #########################################################################
  2251. #                 Twitcher(appName)    
  2252. #========================================================================
  2253. # Author:         DM
  2254. # Description:    This task is intended to select apps from the Process List
  2255. #                menu in System 7.0.  Use LaunchTwitch to handle launching 
  2256. #                or twitching applications.
  2257. #                This routine selects apps from the Process List.
  2258. # Parameters:        appName - app to twitch to.
  2259. # Returns:            0 if twitching to appName fails
  2260. #                    TheCurrentApp - if twitching was successful
  2261. # Examples:            Twitcher("MacWrite 5.0");
  2262. # Assumptions:        None
  2263. #========================================================================
  2264. # History
  2265. #     DMM            5/29/90        created
  2266. #     DMM            6/26/90        streamlined and updated for a11
  2267. #     DMM/KTA        7/31/90        Single twitch and 6.0 compat
  2268. #     KTA            12/20/90    Made the Hide check !
  2269. #    NJV            4/15/91        Added fix for special chars in app name
  2270. #    KTA            8/7/91        Changed logging
  2271. #    KTA            9/26/91        Took out cycling thru the Process List.
  2272. #    JM            2/25/92        Added '~' in 'Hide' exception.
  2273. #########################################################################
  2274. task Twitcher(appName := "") 
  2275. begin
  2276.     if (Global isSys7) 
  2277.         match[menuItem t:"Hide Others" m:[menu o:?menuOrd] ]!;
  2278.     
  2279.     ApplicationMI := match[menuItem t:/≈{appName}≈/ m:[menu o:menuOrd] ]!;
  2280.     if not ( ApplicationMI )    # for special chars in appname
  2281.         ApplicationMI := match[menuItem t:appName m:[menu o:menuOrd] ]!;
  2282.     if ( ApplicationMI ) begin
  2283.         if not(ApplicationMI.t ~= /Hide≈/!) begin
  2284.             select ApplicationMI;
  2285.             AppName := ApplicationMI.t;
  2286.             LogStr("Twitched to {AppName} by way of the process list",3);
  2287.             wait(2);
  2288.             TheCurrentApp := matchApp(1);
  2289.             if(isSubString(appName,TheCurrentApp))        #Check to see if App is frontmost
  2290.                 return(TheCurrentApp);
  2291.             else return(0);
  2292.         end;
  2293.     end;
  2294.     else begin
  2295.         LogStr("Sorry Charlie, Couldn't select '{appName}' from the process list");
  2296.         return(0);
  2297.     end;
  2298. end; # Twitcher()
  2299.  
  2300.  
  2301. #########################################################################
  2302. #                MiniLaunch(appTitle, LaunchApp, SetDir)
  2303. #========================================================================
  2304. # Author:        NJV - DMM
  2305. # Description:    This routine will launch an application on the target
  2306. #                machine(s).  The miniLauncher tool should be the running
  2307. #                application on the target machine(s).  This routine will
  2308. #                type the input parameter appTitle to the target machine
  2309. #                and then type the return key (which is how an application
  2310. #                is launched using miniLauncher.)  The application to be
  2311. #                launched must reside in a folder beneath the miniLauncher
  2312. #                tool in the directory hierarchy. For more information on
  2313. #                the miniLauncher tool, see the read-me that accompanies
  2314. #                the tool.  
  2315. #                MiniLauncher can also open or print documents.  See the
  2316. #                LaunchApp parameter description below for more details.
  2317. #
  2318. # Parameters:    appTitle -    title of the application or document to be launched.
  2319. #                            The title does not have to be complete.  The MiniLauncher
  2320. #                            tool will launch the first application it finds
  2321. #                            starting with the string appTitle.  If LaunchApp
  2322. #                            parameter is not 1, then appTitle will hold the
  2323. #                            document name to be opened or printed.
  2324. #                LaunchApp - 1 to launch application
  2325. #                            0 to launch application via a document
  2326. #                            -1 to print a document (launch app and print)
  2327. #                SetDir    -    1 to set the default directory to that of the
  2328. #                                application
  2329. #                            0 to bypass setting of default directory (will
  2330. #                                end up being MiniLauncher's directory).
  2331. #
  2332. # Returns:        1 - Launched OK
  2333. #                0 - Couldn't launch application (usually due to lack of 
  2334. #                        enough memory on the target machine).
  2335. #
  2336. # Examples:        MiniLaunch('Word');
  2337. #========================================================================
  2338. # History:
  2339. #     NJV-DMM    6/21/90        Created
  2340. #    NJV        11/27/90    Updated for MiniLauncher v.1.3b - added LaunchApp
  2341. #                        and SetDir paramters
  2342. #    KTA        4/14/92        Reimplemented
  2343. #########################################################################
  2344. task MiniLaunch(appTitle, LaunchApp := 1,SetDir := 1) begin
  2345.     returnVal := 0;
  2346.     if not(match[window t:"MiniLauncher" o:1]!)
  2347.     begin
  2348.         MiniLauncher := match[menuitem t:/MiniLauncher≈/ m:[menu t:'']];        # is it in the Apple menu
  2349.         if (MiniLauncher)            # if so select it
  2350.         begin
  2351.             select MiniLauncher;
  2352.             LogStr("Selected Minilauncher");
  2353.             returnVal := 1;
  2354.         end;
  2355.         else
  2356.             LogStr("MiniLauncher is not currently running");
  2357.     end;
  2358.     else
  2359.         returnVal := 1;            # Minilauncher is the front window
  2360.     
  2361.     if(returnVal)
  2362.     begin
  2363.         Println "    -- MiniLauncher --";        # So log reflects what is going down
  2364.         # if LaunchApp is 0 check for newest version of MiniLauncher
  2365.         foo := match [button t:'Options']!;
  2366.         if (LaunchApp <> 1) 
  2367.         begin
  2368.             if (not foo) begin
  2369.                 if (LaunchApp = -1)  # user trying to print document
  2370.                     LogStr("Wrong version of MiniLauncher for printing documents - use v1.3b or newer.");
  2371.                 else
  2372.                     LogStr("Wrong version of MiniLauncher for launching documents - use v1.3b or newer.");
  2373.             end;
  2374.             else
  2375.                 SelectButton('Options');
  2376.             if (LaunchApp = -1)    # user wants to print document
  2377.                 SelectRadioButton('Print Document');
  2378.             else
  2379.                 SelectRadioButton('Open Document');
  2380.             
  2381.             SelectButton("OK");
  2382.         end;
  2383.         else if (foo) 
  2384.         begin
  2385.             SelectButton('Options');
  2386.             SelectRadioButton('Launch Application');
  2387.             if (SetDir)
  2388.                 SelectRadioButton("Application∂'s Directory");
  2389.             else
  2390.                 SelectRadioButton("MiniLauncher∂'s Directory");
  2391.             SelectButton('OK');
  2392.         end;
  2393.  
  2394.         TypeStr(appTitle);
  2395.         SpecialKey(returnKey , "Return Key");
  2396.         if(DialogCheck("An error has occurred", 'OK'))
  2397.         begin
  2398.             returnVal := 0;
  2399.             DialogCheck('','OK');        # Any additional dialogs
  2400.         end;
  2401.         if(returnVal)    
  2402.             MatchApp(0);
  2403.     end;
  2404.     return(returnVal);
  2405. end;  # MiniLaunch()
  2406.  
  2407. #########################################################################
  2408. #            LaunchTwitch(AppName, AliasDir, LaunchApp, SetDir)
  2409. #========================================================================
  2410. # Author:            KTA
  2411. # Description:        This routine determines whether the Operating system is 
  2412. #                    6.0x or 7.0x and launches the application accordingly.  
  2413. #                    6.0x -  Will check the Apple menu to see if the App is 
  2414. #                    currently running and select it if it is. If it is not running
  2415. #                    it will select Mini from the Apple menu and call MiniLaunch(AppName);
  2416. #                    7.0x -  Will check the ProcessList to see if the App is 
  2417. #                    currently running and select it if it is.  if it is not it will
  2418. #                    Select the Apple from the Apple Menu, or the <AliasDir> and then type
  2419. #                    the <AppName> and select the Open menuItem.
  2420. # Parameters:        AppName - Application to be launched/Twitched
  2421. #                    AliasDir -  Folder in the Apple menu that contains <AppName>.
  2422. #                    LaunchApp - 0    Select from Process list - Do not launch the App.
  2423. #                                1    Select from Process list or launch the App if 
  2424. #                                    necessary.
  2425. # Returns:            0 - App did not launch
  2426. #                    1 - App launched fine
  2427. #                    2 - App launched with minimum memory
  2428. # Examples:            LaunchTwitch('MacWrite', "#CoreAliases");
  2429. #                    LaunchTwitch('MacWrite Doc',"#CoreAliases",0);
  2430. # Assumptions:        7.0x -  That the Application (or Alias) is resident in the 
  2431. #                    Apple Menu or the <AliasDir> which contains <AppName> is.
  2432. #========================================================================
  2433. # History:
  2434. # KTA        7/31/90        Created
  2435. # KTA        8/2/90        Added- if not( CurrApp.t ~= /≈{AppName}≈/)
  2436. # DM        9/23/90        Added- Timer()
  2437. # NJV        11/27/90    Added LaunchApp and SetDir parameters
  2438. # KTA        12/10/90    Added-match /≈{AliasDir}≈/ instead of "{AliasDir}"
  2439. # KTA        12/17/90    Added-match Check for error dialogs
  2440. # NJV/KTA    12/18/90    Added-BailFlag
  2441. # KTA        12/20/90    LaunchApp     1 - for 7.0 Finder launch on
  2442. #                                    0 - Finder launch off
  2443. # KTA        1/8/90        Removed Timer()
  2444. # KTA        1/9/90        Changed Exits to Return(0)
  2445. # NJV        1/23/91        Returns 1 if app launch OK, 2 if launch in min mem
  2446. # NJV        1/27/91        Disables Integration Module
  2447. # KTA        2/5/91        Changes loop 10 times to loop 2 times
  2448. # KTA        2/24/91        Reset Global AppVerify befroe returning values - bug
  2449. # KTA        2/25/91        /≈{AliasDir}≈/ to see if correct folder is open
  2450. # KTA        2/25/91        DialogCheck for memory.
  2451. # NJV        3/27/91        Added check for 6.x to see if MiniLauncher is 
  2452. #                        current application.
  2453. # NJV/KTA     4/1/91        Shortened and simplified
  2454. # NJV/KTA     4/8/91        Return 0 if DialogCheck finds memory dialog.
  2455. # KTA         7/18/91        Changed the AliasDir open check
  2456. # KTA         7/26/91        Added PatchLaunchTwitch
  2457. # KTA         8/7/91        Added more logging
  2458. # KTA         9/30/91        Changed verification of AliasDirectory
  2459. # KTA         11/15/91    Changed memory check to include carriage returns.
  2460. # KTA         4/14/92        Reimplemented 6.0x support
  2461. #########################################################################
  2462. Task LaunchTwitch(AppName, AliasDir :="",LaunchApp := 1) begin    
  2463.     global IsSys7;
  2464.     returnVal := 0;
  2465.     Match[application t:?CurrApp];
  2466.     if not( CurrApp ~= /≈{AppName}≈/)         # if its not the current App
  2467.     begin
  2468.         tempTypeSpeed := typespeed(50);
  2469.         global AppVerify, AppTitle, PrevAppTitle, Integration;
  2470.         Temp := AppVerify;
  2471.         PrevAppTitle :=  AppTitle;                # Set previous app to the current app
  2472.         AppVerify := 0;                            # Turn off Application Verification scheme
  2473.         tempIntegrate := Integration;
  2474.         Integration := 0;                        # Turn off any CDEV or DA testing during launch
  2475.         if not (Global PatchLaunchTwitch)         # if we want to patch Launchtwitch
  2476.         begin
  2477.             # Is it in the Apple Menu ?
  2478.             if (match[menuItem t:/≈{AppName}≈/ m:[menu t:""]]) 
  2479.             begin
  2480.                 Selectmenuitem("{appName}", "");        # Select it if it's an Apple MenuItem
  2481.                 returnVal := 1;
  2482.             end;
  2483.             else # Not in Apple Menu
  2484.             begin
  2485.                 if (IsSys7)        # System 7 branch
  2486.                 begin
  2487.                     launchedByProcessList :=Twitcher(Appname);
  2488.                     if ((not launchedByProcessList) and (LaunchApp))     # if App is not already running in the Background
  2489.                     begin
  2490.                         if (AliasDir)                            # If a folder in the Apple Menu contains our App
  2491.                         begin
  2492.                             SelectMenuItem(AliasDir, "");            # Select the Folder
  2493.                             Wait(2);
  2494.                             
  2495.                             if (FindWindow(/≈{AliasDir}≈/))             # Is the right folder open
  2496.                             begin
  2497.                                 typeStr("{appName}");                # Type the appName
  2498.                                 SelectMenuItem('Open','File');        # Select the Open menu item
  2499.                                 LogStr("Launched/Opened - '{AppName}'",3);
  2500.                                 DialogCheck("",'Ok');    # Verify that no problems (like alias not found)
  2501.                                 returnVal := 1;
  2502.                             end;
  2503.                             else 
  2504.                             begin
  2505.                                 LogStr("!@#$% Couldn't open folder titled {AliasDir} containing requested Alias.");
  2506.                                 DialogCheck(/memory≈(≈∂n≈)*/,'OK');        # Check for memory problems
  2507.                             end;
  2508.                         end;
  2509.                         else 
  2510.                             LogStr("!@#$% Couldn't launch - '{AppName}'");
  2511.                     end; # not LaunchByProcessList
  2512.                     else
  2513.                         returnVal := launchedByProcessList;                    
  2514.                 end;# IsSys7
  2515.                 else # Must be a 6.0.x System so we will launch with minilauncher
  2516.                     returnVal := Minilaunch(AppName);    # System 6 branch
  2517.             end; # Not in Apple Menu
  2518.         end;    # Not Global PatchLaunchTwitch
  2519.         else
  2520.             returnVal := (PatchLaunchTwitcher(AppName, AliasDir,LaunchApp));
  2521.  
  2522.         # Memory Checks
  2523.         if (returnVal) # we're OK so far - keep checking
  2524.         begin    
  2525.             for foo := 1 to 2
  2526.                 if(DialogCheck(/memory≈(≈∂n≈)*/,'OK'))         # Check for memory problems
  2527.                     returnVal := 0;                        
  2528.             wait(3);            # Allow app to launch if there is available memory
  2529.         end;
  2530.         
  2531.         ## Check to insure application actually launched
  2532.         Match[application t:?CurrAppl];
  2533.         Match[window o:1 t:?CurWin];    # 6.0 support Da's are not applications
  2534.         if ( CurrAppl ~= /≈{AppName}≈/) or ( CurWin ~= /≈{AppName}≈/) 
  2535.         begin
  2536.             matchApp(0);    # To update the Global gAppTitle to the new App
  2537.             returnVal := 1;
  2538.         end;
  2539.         else # Desired application is not running
  2540.             returnVal := 0;
  2541.             
  2542.         # Reset the global values to there orignial values.
  2543.         AppVerify := temp;    
  2544.         typespeed(tempTypeSpeed);
  2545.         Integration := tempIntegrate;
  2546.         
  2547.     end;    # if not( CurrApp ~= /≈{AppName}≈/)
  2548.     else    # Desired App must be running
  2549.     begin
  2550.         AppTitle := CurrApp;        # Update the global gAppTitle
  2551.         returnVal := 1;
  2552.     end;
  2553.  
  2554.     return(returnVal);
  2555. end; # LaunchTwitch();
  2556.  
  2557.  
  2558. #########################################################################
  2559. #                PatchLaunchTwitcher()
  2560. #========================================================================
  2561. # Author:        KTA
  2562. # Description:    
  2563. # Parameters:    
  2564. # Returns:        
  2565. # Examples:        
  2566. # Assumptions:    
  2567. #========================================================================
  2568. # History:
  2569. #     KTA        7/28/91    Created
  2570. #########################################################################
  2571. task PatchLaunchTwitcher(AppName, AliasDir :="",LaunchApp := 1) 
  2572. begin
  2573.     #    write your own launching mechanisms - set global patchLaunchTwich to true
  2574. end;
  2575.  
  2576. #########################################################################
  2577. #                             IsSubString(str1, str2)
  2578. #=======================================================================
  2579. # Author:              SL
  2580. # Description:        Checks to see if str1 is in str2.
  2581. # Parameters:        str1    :=    Substring to be searched for.
  2582. #                    str2    :=    String.
  2583. # Returns:            0        :=    str1 is not in str2.
  2584. #                    1        :=    str1 is in str2.
  2585. #=======================================================================
  2586. # History:
  2587. #     SL            6/20/90        Created
  2588. #     KTA            9/4/90        Rewrote
  2589. #    JM            2/6/92        Added '=' clause to allow exact matching to
  2590. #                            preclude subStr, which may contain special
  2591. #                            characters (parens, '+', etc.)
  2592. #########################################################################
  2593. task IsSubString(str1, str2) begin
  2594.      if (str2 = str1) or ( str2 ~= /≈"{str1}"≈/) return(1);
  2595.      else return(0);
  2596. end; # isSubString()
  2597.  
  2598.  
  2599. #########################################################################
  2600. #                         FindPos(char, str, startPos)
  2601. #=======================================================================
  2602. # Author:          SL
  2603. # Description:    Finds the first occurence of char in str starting
  2604. #                from startPos.
  2605. # Parameters:    char    :=    A character to be searched for.
  2606. #                str        :=     String.
  2607. #                startPos:=    Starting position to be searched.
  2608. # Returns:        0        :=    Char is not in str starting from
  2609. #                            startPos.
  2610. #                pos        :=     Char position of its first occurence
  2611. #                            starting from startPos.
  2612. #=======================================================================
  2613. # History:
  2614. #    SL        6/20/90            Created
  2615. #########################################################################
  2616. task FindPos(char, str, startPos:= 1)
  2617. begin
  2618.     numStr := card str;
  2619.     
  2620.     # If start position is greater than the string length, return 0 #
  2621.     if (startPos > numStr)
  2622.         return(0);
  2623.     
  2624.     for i:= startPos to numStr do
  2625.         begin
  2626.             if (char = str[i])
  2627.                 return(i);
  2628.         end; # for
  2629.     return(0);
  2630. end; # findPos()
  2631.  
  2632. #########################################################################
  2633. #                         Substring(String,StartChar,NumChar)
  2634. #=======================================================================
  2635. # Author:          PF 
  2636. # Description:    returns the first NumChar characters of the passed String
  2637. #                starting at StartChar.
  2638. # Parameters:    String - String to use
  2639. #                StartChar - Character to start making substring from
  2640. #                NumChar - Integer number of characters to return
  2641. # Returns:        string
  2642. # Assumptions:    none
  2643. #=======================================================================
  2644. # History:
  2645. #    PF        8/23/90        Created
  2646. #    PF        8/27/90        Updated to handle begin anywhere in string
  2647. #    JM        2/25/92        Added space between 'Card' and 'String'.
  2648. ##########################################################################
  2649. task Substring(String,StartChar,NumChar) begin
  2650.     # first see if number of characters is greater then length of string
  2651.     # and return the whole end of the string if it is.
  2652.     if (NumChar > ((card String) - StartChar + 1)) begin
  2653.         return (Substring (String,StartChar,((card String) - StartChar) +1));
  2654.         
  2655.     end;
  2656.     else begin
  2657.         # create a string of first NumChar characters and return it.
  2658.         NewString:="";                            #start with an empty string
  2659.         for CharCount :=StartChar to ((StartChar + NumChar) - 1)
  2660.             NewString := NewString + String[CharCount];
  2661.             return (NewString);
  2662.     end;
  2663. end; #Substring task
  2664.  
  2665. ########################################################################
  2666. #                     DrawShapeFrame(specifier := 1,ltrb)                        
  2667. #=======================================================================
  2668. # Author:         DMM                        
  2669. # Description:    Click drags a rectangular frame in the specified window.                                            
  2670. # Parameters:    specifier    window to draw in; defaults to ordinality 1            
  2671. #                ltrb         {"random"} or {l,t,r,b} of rect to draw 
  2672. #                inset         defines the drawing area relative to the 
  2673. #                            window rectangle
  2674. # Returns:        nada
  2675. #=======================================================================
  2676. # History:
  2677. # DM        5/22/90        created
  2678. # DM        9/24/90        Use GetXYRandom to get coords, change
  2679. #                        ltrb param to a list.  Addd inset param
  2680. #                        so it can be passed to GetXYRandom.
  2681. # DM        9/24/90        Generalized and rolled into control.lib
  2682. #########################################################################
  2683. task DrawShapeFrame(spec := 1,ltrb := {"random"},inset := {0,0,0,0}) 
  2684. begin
  2685.     temp := global DisableAllLogging;
  2686.     global DisableAllLogging := 1;
  2687.     mTemp := mouseSpeed(10);
  2688.     
  2689.     if (ltrb[1] = "random")  # get random coordinates for the rect
  2690.     begin
  2691.         lrel := "random"; rRel := "random";
  2692.     end;
  2693.     else                     # set specific coordinates for the rect
  2694.     begin
  2695.         lRel := ltrb[1]; tRel := ltrb[2]; rRel := ltrb[3]; bRel := ltrb[4];
  2696.     end;
  2697.     # do the drag
  2698.     lT := MoveRelativeToWindow(lRel,tRel,spec,0,inset);
  2699.     rB := MoveRelativeToWindow(rRel,bRel,spec,1,inset);
  2700.     
  2701.     mouseSpeed(mTemp);
  2702.     global DisableAllLogging := temp;
  2703.     
  2704.     left := lT[1]; top := lT[2]; right := rB[1]; bott := rB[2];
  2705.     LogStr("Click-Dragged frame from ∂({left},{top}∂) to ∂({right},{bott}∂).");
  2706. end;
  2707.  
  2708. #########################################################################
  2709. #            SelToolFromWindow(the_tool,specifier,WhichToolStr)
  2710. #========================================================================
  2711. # Author:        DMM
  2712. # Description:    This task selects tools that are embedded in document
  2713. #                windows
  2714. # Parameters:    the_tool -    tool position in palette counting left to right,
  2715. #                        top to bottom
  2716. #                specifier - ordinality of doc window containing tools
  2717. #                WhichToolStr - String name of tool
  2718. # Returns:      1 - selected tool
  2719. #                0 - couldn't select tool
  2720. # Assumptions:    Tools are selected from the front window, tool rectangles
  2721. #                are the same size
  2722. #                as a window.
  2723. # Examples:        SelToolFromWindow(1,2);
  2724. #========================================================================
  2725. # Revisions:
  2726. #    created 6/1
  2727. #  9/6/91    KTA        Added WhichToolStr for output purposes
  2728. #  4/8/92    ML        Changed variable named 'tool' to 'the_tool' for 
  2729. #                    compatibility with VU 2.0
  2730. #  4/8/92    ML        Changed (the_tool mod toolsAcross != 0)
  2731. #                    to (the_tool mod toolsAcross = 0) for 
  2732. #                    compatibility with VU 2.0
  2733. #########################################################################
  2734. task SelToolFromWindow(the_tool,WindSpecifier := 0, WhichToolStr :='') begin
  2735.     global     specifier, toolsAcross, toolsDown, toolRect;
  2736.     if (WindSpecifier)
  2737.         specifier := WindSpecifier;
  2738.     else if not(specifier)
  2739.         specifier := 1;
  2740.         
  2741.     if not (toolRect) 
  2742.     begin
  2743.         LogStr("NOTE:  Tool globals are not set up correctly",2);
  2744.         noErr := 0;
  2745.     end;
  2746.     else
  2747.     begin
  2748.         DWindow := match [window o:specifier r:?windRect]!;
  2749.         Str1 := "Could not find a window with ordinality '{specifier}'";
  2750.         
  2751.         if DWindow begin
  2752.             xMove := (toolRect[3] - toolRect[1])/toolsAcross;
  2753.             yMove := (toolRect[4] -  toolRect[2])/toolsDown;
  2754.             xStart := windRect[1] + toolRect[1] - xMove/2;
  2755.             yStart := windRect[2] + toolRect[2] - yMove/2;
  2756.             
  2757.             if (the_tool < toolsAcross)
  2758.                 xTool := the_tool * xmove;
  2759.             else begin
  2760.                 if ((the_tool mod toolsAcross) <> 0)
  2761.                     xTool := ((the_tool mod toolsAcross)) * xMove;
  2762.                 else
  2763.                     xTool := ((toolsAcross)) * xMove;
  2764.             end;
  2765.             if (the_tool mod toolsAcross = 0) 
  2766.                 yTool := (the_tool/toolsAcross) * yMove;
  2767.             else
  2768.                 yTool := (the_tool/toolsAcross +1) * yMove;
  2769.             
  2770.             xTool := xTool + xStart; 
  2771.             yTool := yTool + yStart; 
  2772.             
  2773.             move a: {xTool, yTool};
  2774.             click;
  2775.             if (WhichToolStr)
  2776.                 Str1 := "Clicked on the '{WhichToolStr}' tool - number {the_tool} at ∂({xTool},{yTool}∂)";
  2777.             else 
  2778.                 Str1 := "Clicked on tool number {the_tool} at ∂({xTool},{yTool}∂)";
  2779.             noErr := 1;
  2780.         end;
  2781.         else begin
  2782.             noErr := 0;
  2783.         end;
  2784.         LogStr(Str1);
  2785.     end;
  2786.     return noErr;    
  2787. end; # SelToolFromWindow()
  2788.  
  2789. #########################################################################
  2790. #            SelToolFromPallette(the_tool,specifier,WhichToolStr)
  2791. #========================================================================
  2792. # Author:        DMM
  2793. # Description:        This task selects tools from palettes that VU sees as
  2794. #                    separate windows
  2795. # Parameters:        the_tool -    tool position in palette counting left to right,
  2796. #                                top to bottom
  2797. #                    specifier -    holds title or ordinality of palette window
  2798. #                    WhichToolStr - String name of tool
  2799. # Return Values:    1 - selected tool
  2800. #                    0 - couldn't select tool
  2801. # Assumptions:        Tool rectangles are the same size, VU can see the palette
  2802. #                    as a window (tear off menus are torn off).
  2803. # Examples:            SelToolFromPallette(1);
  2804. #========================================================================
  2805. # Revisions:
  2806. #    created 6/1
  2807. #  9/6/91    KTA        Added WhichToolStr for output purposes
  2808. #  4/8/92    ML        Changed variable named 'tool' to 'the_tool' for 
  2809. #                    compatibility with VU 2.0
  2810. #  4/8/92    ML        Changed (the_tool mod toolsAcross != 0)
  2811. #                    to (the_tool mod toolsAcross = 0) for 
  2812. #                    compatibility with VU 2.0
  2813. #########################################################################
  2814. task SelToolFromPallette(the_tool,WindSpecifier := 0, WhichToolStr :='') begin
  2815.     global     specifier, toolsAcross, toolsDown, headerHeight;
  2816.     if (WindSpecifier)
  2817.         specifier := WindSpecifier;
  2818.     else if not(specifier)
  2819.         specifier := 1;
  2820.  
  2821.     if not (headerHeight) 
  2822.     begin
  2823.         LogStr("NOTE:  Tool globals are not set up correctly",2);
  2824.         noErr := 0;
  2825.     end;
  2826.     else
  2827.     begin
  2828.     
  2829.         if (specifier > 0) begin        # specifier = ordinality
  2830.             DWindow := match [window o:specifier r:?windRect]!;
  2831.             Str1 := "Could not find a palette of ordinality {specifier}";
  2832.         end;
  2833.         else begin                        # specifier = title
  2834.             DWindow := match [window t:specifier r:?windRect]!;
  2835.             Str1 := "Could not find a palette titled '{specifier}'";
  2836.         end;
  2837.         
  2838.         if DWindow begin
  2839.             xMove := (windRect[3] - windRect[1])/toolsAcross;
  2840.             yMove := (windRect[4] - windRect[2] - headerHeight)/toolsDown;
  2841.             xStart := windRect[1] - xMove/2;
  2842.             yStart := windRect[2] - yMove/2 + headerHeight;
  2843.             
  2844.             if (the_tool < toolsAcross)
  2845.                 xTool := the_tool * xmove;
  2846.             else begin
  2847.                 if ((the_tool mod toolsAcross) <> 0)
  2848.                     xTool := ((the_tool mod toolsAcross)) * xMove;
  2849.                 else
  2850.                     xTool := ((toolsAcross)) * xMove;
  2851.             end;
  2852.             if (the_tool mod toolsAcross = 0) 
  2853.                 yTool := (the_tool/toolsAcross) * yMove;
  2854.             else
  2855.                 yTool := (the_tool/toolsAcross +1) * yMove;
  2856.             xTool := xTool + xStart;
  2857.             yTool := yTool + yStart;
  2858.             move a:{xTool, yTool};
  2859.             click;
  2860.             if (WhichToolStr)
  2861.                 Str1 := "Clicked on the '{WhichToolStr}' tool - number {the_tool} at ∂({xTool},{yTool}∂)";
  2862.             else 
  2863.                 Str1 := "Clicked on tool number {the_tool} at ∂({xTool},{yTool}∂)";
  2864.             noErr := 1;
  2865.         end;
  2866.         else begin
  2867.             err := 0;
  2868.         end;
  2869.         LogStr(Str1);
  2870.     end;
  2871.     return err;    
  2872. end; # SelToolFromPallette()
  2873.  
  2874. #########################################################################
  2875. #                            DoDraw()
  2876. #========================================================================
  2877. # Author:        DM (x41220)
  2878. # Description:    Selects drawing tool and uses it.
  2879. # Parameters:    PaletteType - Type of palette
  2880. #                    1 - Palette is a part of document window
  2881. #                    2 - Palette is it's own window
  2882. # Returns:        Nothing
  2883. # Examples:        DoDraw();
  2884. # Assumptions:    That the application sets up the appropriate globals
  2885. #                ( see SelToolFromWindow or SelToolFromPalette 
  2886. #                Global ToolMultiplier,ToolList,Inset,Specifier,ToolRect,
  2887. #                ToolsAcross,ToolsDown,HeaderHeight)
  2888. #                if SelToolFromWindow() - HeaderHeight is not defined
  2889. #                if SelToolFromPalette() - ToolRect is not defined
  2890. # Applications:        
  2891. #========================================================================
  2892. # History:
  2893. # 9/19/91    KTA    Added global ToolMultiplier
  2894. # 10/29/91    KTA    Added global DrawWindow
  2895. #  4/8/92    ML    Changed variable named 'tool' to 'the_tool' for 
  2896. #                compatibility with VU 2.0
  2897. #########################################################################
  2898. task DoDraw(PaletteType := 1) begin 
  2899.     Global ToolMultiplier,ToolList,Inset,Specifier,ToolRect,ToolsAcross,ToolsDown,HeaderHeight,DrawWindow;
  2900.     if not(DrawWindow)
  2901.         DrawWindow := 0;
  2902.     numTools := card(toolList);
  2903.     NumShapes := numTools * ToolMultiplier;
  2904.     LogStr("--------- Preparing to draw {NumShapes} random shapes -------",3);
  2905.     for x := 1 to NumShapes
  2906.     begin
  2907.         the_tool := random(1,numTools);
  2908.         if (PaletteType = 1)                # Tool palette is part of document window
  2909.             SelToolFromWindow(toolList[the_tool],,'Random');        # select a random tool
  2910.         else if (PaletteType = 2)            # Tool palette is a seperate window
  2911.             SelToolFromPallette(toolList[the_tool],,'Random');        # select a random tool
  2912.         DrawShapeFrame(DrawWindow,,inset);             # draw in a random frame in Global DrawWindow
  2913.     end;
  2914. end;
  2915.  
  2916. #########################################################################
  2917. #                    DoText (NextLineKey, Specifier, inset)
  2918. #========================================================================
  2919. # Author:        ML
  2920. #    
  2921. # Description:    This routine will choose a random font size (from global fontSizeList) 
  2922. #                and multiple random font styles (from global fontStyleList) for each of 
  2923. #                the fonts in the global fontlist. The text defined in the global TextStr,
  2924. #                followed by the chosen font, size and styles will then be typed.  
  2925. #                It will then either type the key required to move to the next line, 
  2926. #                or move to a random position and click. 
  2927. #                        
  2928. # Parameters:    NextLineKey - How to move to the next line
  2929. #                              0 Pointer will randomly move and click
  2930. #                              1 Return Key - DEFAULT
  2931. #                              2 Enter Key
  2932. #                              3 Down Arrow Key
  2933. #                              4 Tab Key
  2934. #                Specifier - Use if 0 is passed to NextLineKey.  Holds title or ordinality of
  2935. #                            window to randomly move and click in.  Default is "Untitled".
  2936. #                Inset    -   Use if 0 is passed to NextLineKey.  Inset from window rect for 
  2937. #                            MoveRelativeToWindow.  Default is {30,30,30,30}.                 
  2938. #    
  2939. # Returns:      none
  2940. #    
  2941. # Examples:        DoText (0)
  2942. #                
  2943. # Assumptions:    This routine cannot be used if names, sizes or styles are chosen via dialog box
  2944. #                (i.e. Excel).    
  2945. #    
  2946. #                Your script places the cursor in the starting position where you want the first
  2947. #                text string to be typed before you call DoText().  If you are passing 0 to 
  2948. #                NextLineKey (you want pointer to randomly move and click), you script must choose
  2949. #                the text tool, close all tool palette windows, and click in the starting position
  2950. #                where you want the first TextStr to be typed before you call DoText().
  2951. #    
  2952. #                Some apps (i.e. Pagemaker and Works) use the menu item “Normal” instead of “Plain”
  2953. #                in describing font style.  Is these cases, you must replace the correct 
  2954. #                menuitem name with a call to ReplaceItem(). for example:
  2955. #                Global FontStyleList := Replaceitem('Plain', 'Normal', FontStyleList);
  2956. #========================================================================
  2957. # History:
  2958. #    ML    8/16/91        Created
  2959. #    KA    9/04/91        Added Specifier
  2960. #    KA    9/21/91        Added call to Find Menu to save location of menus
  2961. #                    Also changed functionality to type the global textStr
  2962. #                    for each item in the global fontlist and choose a random 
  2963. #                    size and style.  Styles will not be double selected for any
  2964. #                    one text string.
  2965. #    ML    2/12/92        Added inset parameter
  2966. #########################################################################
  2967. task DoText(NextLineKey := 1, Specifier := 0, inset:= {30,30,30,30}) 
  2968. begin
  2969.     Global fontList,fontSizeList,fontStyleList,textStr;
  2970.     
  2971.     numFontSize := card(fontSizeList);            #counts number of sizes in fontSizeList
  2972.     numFontStyle := card(fontStyleList);        #counts number of styles in fontStyleList
  2973.     println;
  2974.     LogStr("    ===========  DoText    - Font tests ===========");
  2975.     FontMenu := FindMenu(fontList[1]);            # Find the menus - Hierarchy or not 
  2976.     StyleMenu := FindMenu('Bold');                # Save the Menu descriptors so we don't have to 
  2977.     SizeMenu := FindMenu(fontSizeList[1]);        # Match the items each time
  2978.     
  2979.     for each myFont in FontList                 # For every font in Global FontList
  2980.     begin                                        
  2981.                                                 # Random values for Sizes and Styles
  2982.         mySize := random(1,numFontSize);        # Random # between 1 and the # of sizes
  2983.  
  2984.         SelectMenuItem(myFont,FontMenu[1],FontMenu[2]);    # Select the font from the Font menu
  2985.  
  2986.         SelectMenuItem(fontSizeList[mySize],SizeMenu[1],SizeMenu[2]);    # Select the size from the size menu    
  2987.                     
  2988.         if (numFontStyle) begin
  2989.             NumStyle := random(1,numFontStyle);        # Random # between 1 and the # of styles
  2990.             LogStr("Choosing {NumStyle} font styles");
  2991.             CurrentStyleList := fontStyleList;        # Save copy of Global FontStyleList
  2992.             CurrentnumFontStyle := numFontStyle;    # Save copy of number of style in FontStyleList
  2993.             for i:= 1 to NumStyle 
  2994.             begin
  2995.                 myStyle := random(1,CurrentnumFontStyle);    # choose a random number between 1 and the number of styles available
  2996.                 SelectMenuItem(CurrentStyleList[myStyle],StyleMenu[1],StyleMenu[2]);        # Select the style from the style menu
  2997.                 CurrentStyleList := RemoveItem(CurrentStyleList[myStyle],CurrentStyleList);    # After selecting a Style remove it from available styles so we don't reselect it.
  2998.                 CurrentnumFontStyle := CurrentnumFontStyle - 1;        #Decrement number of styles available since we removed an item
  2999.             end;
  3000.     
  3001.             StylesSelected:= "";        # Initialize string containing styles chosen
  3002.             #### Collect all the checked styles
  3003.             if (StyleMenu[2] = "")        # IF - it's not hierarchical
  3004.                 StylesSelectedList := Collect [menuItem  c:'' m:[menu t:StyleMenu[1]]]!;    #see if it is checked
  3005.             else                        # Is Hierarchical
  3006.                 StylesSelectedList := Collect[menuItem  c:'' m:[menuitem t:StyleMenu[1] m:[menu t:StyleMenu[2]]]]!;    #see if it is checked
  3007.     
  3008.             for each StyleItem in StylesSelectedList
  3009.                 StylesSelected:= StylesSelected + " " + StyleItem.t;    #if so, add to string
  3010.         end;
  3011.         else
  3012.             StylesSelected := '';
  3013.             
  3014.         SizeSelected:= fontSizeList[mySize];                        #Assign size chosen to variable
  3015.  
  3016.         TypeStr("{textStr} - {myFont} {SizeSelected} {StylesSelected}");
  3017.             #type the text string, font, size and styles chosen
  3018.             
  3019.         ### For more than 1 line of text a new line must be selected
  3020.         if (NextLineKey = 0)                                         #you want random move and click
  3021.         begin                
  3022.             theWind := FindWindow(Specifier);
  3023.             if theWind 
  3024.             begin
  3025.                 windOrd := theWind.o;
  3026.                 title := theWind.t;
  3027.                 MoveRelativeToWindow('random','random',windOrd,2,inset);    #move pointer to a random
  3028.             end;
  3029.         end;
  3030.         
  3031.         ### Cases of Keystrokes to move to next line
  3032.         if (NextLineKey = 1)
  3033.             SpecialKey(returnKey,"Return Key");
  3034.         else if (NextLineKey = 2)
  3035.             SpecialKey(enterKey,"Enter Key");
  3036.         else if (NextLineKey = 3)
  3037.             SpecialKey(downarrowKey,"Down Arrow Key");
  3038.         else if (NextLineKey = 4)
  3039.             SpecialKey(tabKey,"Tab Key");
  3040.     end;
  3041.     if (numTextstrings > 1) 
  3042.         LogStr("Typed '{textStr}' {numTextstrings} times.");        #send summary to output file
  3043. end; # DoText()
  3044.  
  3045. ########################################################################
  3046. #                        PageSetup( WhichDevice )
  3047. #=======================================================================
  3048. # Author:             KTA
  3049. # Description:        For PageSetup routines
  3050. # Parameters:        Nada
  3051. # Returns:            None
  3052. #=======================================================================
  3053. # History:
  3054. # KTA 2/25/91 Created
  3055. ########################################################################
  3056. task PageSetup(WhichDevice := "LaserWriter") 
  3057. begin
  3058.     if ( WhichDevice = "LaserWriter")
  3059.     begin
  3060.         SelectMenuItem("Page Setup", "File");    #To select Page SetUp…
  3061.         wait(1);
  3062.         SpecialKey(returnKey, 'Return Key');    #To Select the Default-'OK'
  3063.         wait(1);
  3064.     end;
  3065. end; # PageSetup()
  3066.  
  3067. ########################################################################
  3068. #                        Print()
  3069. #=======================================================================
  3070. # Author:             KTA
  3071. # Description:        For Print routines
  3072. # Parameters:        Nada
  3073. # Returns:            None
  3074. #=======================================================================
  3075. # History:
  3076. # KTA 8/19/91 Created
  3077. ########################################################################
  3078. task Printer() 
  3079. begin
  3080.     if     (global PrintTest)
  3081.     begin
  3082.         SelectMenuItem("Print", "File");        #To select Print
  3083.         wait(2);
  3084.         SpecialKey(returnKey, 'Return Key');    #To Select the Default-'OK'
  3085.     end;
  3086. end; # Printer()
  3087.  
  3088.  
  3089. #########################################################################
  3090. #                            IsNumber(whatAmI)
  3091. #========================================================================
  3092. # Author:            NJV
  3093. # Description:        This routine determine whether the input parameter is
  3094. #                    a number or not.  This could be done directly in-line,
  3095. #                    but to avoid Developer's having to modify their code,
  3096. #                    I updated this routine so that scripts will still work
  3097. #                    properly unmodified.
  3098. # Parameters:        whatAmI - item to check
  3099. # Returns:            true - the parameter is a number
  3100. #                    false - the parameter is not a number
  3101. # Examples:            IsNumber("Hello");
  3102. # Assumptions:        None
  3103. #========================================================================
  3104. # History:
  3105. #    NJV        5/22/90        Created
  3106. #    NJV        6/25/91        Now uses TypeOf() VU function
  3107. #########################################################################
  3108. task IsNumber(whatAmI) begin
  3109.     return((TypeOf(whatAmI) = 'integer'));
  3110. end; # IsNumber()
  3111.  
  3112. #########################################################################
  3113. #                        PtInRect(thePoint,theRect)
  3114. #========================================================================
  3115. # Author:            NJV
  3116. # Description:        This routine determines whether or not thePoint 
  3117. #                    is contained within theRect (including borders). 
  3118. # Parameters:        thePoint - a list of two integers
  3119. #                    theRect - holds the coordinates of the rectangle.
  3120. # Returns:            true - point lies in the rectangle.
  3121. #                    false - point does NOT lie in the rectangle.
  3122. # Examples:            isIt := PtInRect(thePoint,theRect).
  3123. # Assumptions:        None
  3124. #========================================================================
  3125. # History:
  3126. #    NJV        9/18/90        Created
  3127. #########################################################################
  3128. task PtInRect(thePoint,theRect) begin
  3129.     return( ((thePoint[1] >= theRect[1]) and (thePoint[1] <= theRect[3]))
  3130.             and ((thePoint[2] >= theRect[2]) and (thePoint[2] <= theRect[4])) );
  3131. end;
  3132.  
  3133.  
  3134. #########################################################################
  3135. #                         CenterofScreenClick()
  3136. #=======================================================================
  3137. # Author:          KTA
  3138. # Description:    Clicks in the center of main screen
  3139. # Parameters:    none
  3140. # Returns:        Nada
  3141. #=======================================================================
  3142. # History:
  3143. #    KTA        12/05/90    Added [m:True] to make sure the right screen
  3144. #########################################################################
  3145. task CenterofScreenClick() begin
  3146.     Match[screen r:?x m:true];
  3147.     w := ((x[3]-x[1])/2);
  3148.     h := ((x[4] - x[2])/2);
  3149.     move a:{w,h};
  3150.     click;
  3151.     LogStr('Moved to the center of the screen and clicked');
  3152. end; # CenterofScreenClick()
  3153.  
  3154.  
  3155.  
  3156. #########################################################################
  3157. #                          RemoveItem(Item,List)
  3158. #========================================================================
  3159. # Author:        KA & JM
  3160. # Description:    This routine was designed to remove items from lists.  
  3161. # Parameters:    Item - Item to be removed from the list
  3162. #                List - any list
  3163. # Returns:        Newlist := if Item is removed from List
  3164. #                0 := if Item is not contained in List
  3165. #========================================================================
  3166. # History:
  3167. #    KA & JM        8/19/91        Created
  3168. #########################################################################
  3169. task RemoveItem(Item,list)
  3170. begin    
  3171.     origList := List;                        # Save original list
  3172.     if (isMember(item,list))                # Is it item in list
  3173.     begin
  3174.         NumItems:= card(list);
  3175.         for WhichItem := 1 to NumItems
  3176.         begin
  3177.             if (list[WhichItem] = Item)
  3178.             begin
  3179.                 Newlist := Remove(WhichItem, list);    # Remove item from list
  3180.                 liststring := '';
  3181.                 for numtimes := 1 to (Card(origList)-1)        # Build String for output
  3182.                     liststring := liststring + origList[numTimes] + ', ';
  3183.                 
  3184.                     liststring := liststring + origList[Card(origList)];
  3185.  
  3186.                 #println "The item '{item}' has been removed from the '{WhichItem}' position of list '∂{ {liststring} ∂}'";
  3187.                 return(Newlist);
  3188.             end;
  3189.         end;
  3190.     end;
  3191.     Else 
  3192.         Return(0);
  3193. end; # RemoveItem()    
  3194.  
  3195. #########################################################################
  3196. #             ReplaceItem(ItemtoBeReplaced, ReplaceItem, List)
  3197. #========================================================================
  3198. # Author:        KA (x45604)
  3199. # Description:    This routine was designed to replace items in lists.  
  3200. # Parameters:    ItemtoBeReplaced - Item to be replaced from the list
  3201. #                ReplaceItem - Item which will now be a part of the list
  3202. #                List - any list
  3203. # Returns:        Newlist := if ItemtoBeReplaced is replaced from List
  3204. #                0 := if ItemtoBeReplaced is not contained in List
  3205. #========================================================================
  3206. # History:
  3207. #    KA        9/11/91        Created
  3208. #########################################################################
  3209. task ReplaceItem(ItemtoBeReplaced, ReplaceItem,List)
  3210. begin    
  3211.     origList := List;                        # Save original list
  3212.     if (isMember(ItemtoBeReplaced,list))                # Is it item in list
  3213.     begin
  3214.         NumItems:= card(list);
  3215.         for WhichItem := 1 to NumItems
  3216.         begin
  3217.             if (list[WhichItem] = ItemtoBeReplaced)
  3218.             begin
  3219.                 Newlist := Replace(ReplaceItem,WhichItem, list);    # replace item from list
  3220.                 liststring := '';
  3221.                 for numtimes := 1 to (Card(origList)-1)        # Build String for output
  3222.                     liststring := liststring + origList[numTimes] + ', ';
  3223.                 
  3224.                     liststring := liststring + origList[Card(origList)];
  3225.  
  3226.                 #println "The item '{ItemtoBeReplaced}' has been replaced with '{ReplaceItem}'from the '{WhichItem}' position of list '∂{ {liststring} ∂}'";
  3227.                 return(Newlist);
  3228.             end;
  3229.         end;
  3230.     end;
  3231.     Else 
  3232.         Return(0);
  3233. end; # ReplaceItem()    
  3234.  
  3235. #########################################################################
  3236. #                             Timer(timeParam)
  3237. #=======================================================================
  3238. # Author:              DM
  3239. # Description:        Calculates the time between two time descriptors 
  3240. # Parameters:        timeParam - Specifier - what to return
  3241. #                    1 - return ({"{theHour}:{theSec}",theHour,theSec});
  3242. #                    2 - return (("{theMonth}/{theDay}/{theYear}"))
  3243. #                    3 - return (theTime) - full descriptor
  3244. #                    4 - CurrentTime - formatted
  3245. # Example:            Timer(1);
  3246. #=======================================================================
  3247. # History:
  3248. # DM    9/04/90        Created
  3249. # KTA    7/25/91     Added Case 4 - Current time
  3250. # JM    2/14/92        Fixed Timer(4) for hours between 12AM and 1AM
  3251. #                        Add leading zeros for if theHour < 100 (1:00AM)
  3252. #########################################################################
  3253. task Timer(timeParam:=1) begin
  3254.     theTime := match [time h:?theHour s:?theSec d:?theDay m:?theMonth y:?theYear];
  3255.     if (timeParam = 1) begin
  3256.         return ({"{theHour}:{theSec}",theHour,theSec});
  3257.     end;
  3258.     else if (timeParam = 2) begin 
  3259.         return (("{theMonth}/{theDay}/{theYear}"));
  3260.     end;
  3261.     else if (timeParam = 3) begin 
  3262.         return (theTime);
  3263.     end;
  3264.     else if (timeParam = 4) 
  3265.     begin 
  3266.         HourString := numToStr (theHour);
  3267.         while (Card(HourString) < 4)
  3268.             HourString := '0' + HourString;
  3269.         HourString := HourString[1] + HourString[2] + ':' + HourString[3] + HourString[4];
  3270.         SecString := numToStr (theSec);
  3271.         if( Card(SecString) = 1) 
  3272.             SecString := '0' + SecString;
  3273.         CurrentTime := HourString + ':' + SecString;
  3274.         Println "The current time is - ",CurrentTime;
  3275.         Return(CurrentTime);
  3276.     end;
  3277. end; # Timer()
  3278.  
  3279. #########################################################################
  3280. #                             ETime(time1, time2)
  3281. #=======================================================================
  3282. # Author:              DM
  3283. # Description:        Calculates the time between two time descriptors 
  3284. # Parameters:        time1 - initial time
  3285. #                    time2 - end time
  3286. # Returns:            "{eh}:{em}:{es}" - Difference between the two
  3287. # Example:            ETime(time1, time2);
  3288. #=======================================================================
  3289. # History:
  3290. # DM     9/04/90        Created
  3291. #########################################################################
  3292. task ETime(time1, time2) begin
  3293.     h1:= 0; h2 := 0; m1:= 0; m2 := 0; 
  3294.     t1 := time1.h; t2 := time2.h; s1 := time1.s; s2 := time2.s;
  3295.     if(t1 > t2) begin
  3296.         t1 := time2.h; t2 := time1.h; s1 := time2.s; s2 := time1.s;
  3297.     end;
  3298.     h1 := t1/100;                            # get h1
  3299.     m1 := t1 mod 100;                         # get m1
  3300.     h2 := t2/100;                            # get h2
  3301.     m2 := t2 mod 100;                         # get m2
  3302.     eh := h2-h1; em := m2-m1;                # eh = elapsed hours, em = elapsed mins
  3303.     if(em<0) begin
  3304.         em := em + 60; eh := eh -1;
  3305.     end;
  3306.     es := s2 - s1;
  3307.     if(es<0) begin
  3308.         if (em>0) begin
  3309.             es := es + 60; em := em -1;
  3310.         end;
  3311.         else if (eh>0) begin
  3312.             es := es + 60; eh := eh - 1; em := 59;
  3313.         end;
  3314.         else begin
  3315.             es := -es;
  3316.         end;
  3317.     end;
  3318.     return ("{eh}:{em}:{es}");
  3319. end; # ETime()
  3320.  
  3321. #########################################################################
  3322. #                             DoSpecialTest(WhichTest)
  3323. #=======================================================================
  3324. # Author:              KTA
  3325. # Description:        Hook for any special tests all the Standard QuickLooks 
  3326. #                    Call this task 3 times. 
  3327. # Parameters:        WhichTest - Scriptor defined tests.
  3328. # Returns:            Whatever you want.
  3329. # Example:            DoSpecialTest(1);
  3330. #=======================================================================
  3331. # History:
  3332. # KTA     9/04/90        Created
  3333. #########################################################################
  3334. task DoSpecialTest( WhichTest := 0) 
  3335. begin
  3336.     if ( WhichTest = 1 )
  3337.     begin
  3338.         println;
  3339.         Timer(4);        # Current time
  3340.         global startTime := Timer(3);
  3341.         Println "Starting the timer";
  3342.     end;
  3343.  
  3344.     if (global Spectest) 
  3345.     begin
  3346.         if ( WhichTest = 1 )
  3347.         begin
  3348.             SelectMenuItem("Show Balloons");
  3349.         end;
  3350.         if ( WhichTest = 2 )
  3351.         begin
  3352.             LogStr("About to begin middle Special Tests");
  3353.             SelectMenuItem("Print", "File");
  3354.             SpecialKey(returnKey,"Return Key");
  3355.             SpecialKey(returnKey,"Return Key");
  3356.             Wait(5);
  3357.             SelectMenuItem("Print", "File");
  3358.             SpecialKey(returnKey,"Return Key",2);
  3359.             SelectMenuItem("Hide Balloons");
  3360.         end;
  3361.     end;
  3362. end; # DoSpecialTest()
  3363.  
  3364. task DoSpecTestsInitial() 
  3365. begin
  3366.     DoSpecialTest(1);
  3367. end;
  3368. task DoSpecTestsMiddle() 
  3369. begin
  3370.     DoSpecialTest(2);
  3371. end;
  3372.  
  3373.  
  3374. #########################################################################
  3375. #                Scrapbook(requestElement,ccpFlag,pasteFlag)
  3376. #========================================================================
  3377. # Author:        KTA
  3378. # Description:    This routine will select the scrapbook, scroll to the
  3379. #                designated requestElement position, select Cut, Copy, Paste,
  3380. #                or Clear from the Edit menu, close the scrapbook if under System
  3381. #                6.0.x, and then select Paste if the pasteFlag parameter is 1.
  3382. # Parameters:    requestElement - the element in the scrapbook to scroll to
  3383. #                ccpFlag -    1 for copy
  3384. #                            2 for cut
  3385. #                            3 for paste
  3386. #                            4 for clear
  3387. #                pasteFlag - 1 to paste after closing Scrapbook
  3388. #                            0 not to paste after closing Scrapbook
  3389. # Returns:        0 - Couldn't complete operation
  3390. #                element - Scrapbook element that operation took place on
  3391. # Examples:        Scrapbook(2) will scroll the horizontal bar to the
  3392. #                second entry and then copy, close and paste.
  3393. # Assumptions:    That the scrollbars are present. That the string
  3394. #                'Scrapbook' appear somewhere in the name
  3395. #========================================================================
  3396. # History:
  3397. #     KTA        11/28/89    Created
  3398. #    KTA     5/14/90        handles its own scrollbars instead of ScrollWindow() 
  3399. #                        Checks for enabled scrollbars
  3400. #                        MatchApp(0); for App verification
  3401. #    NJV        7/3/90        (x,y) parameters are now just (x)
  3402. #                        added copyFlag - 1 if copy, 0 if cut
  3403. #    NJV        7/5/90        Added pasteFlag - 1 if paste, 0 if don't paste
  3404. #                        Added error checking to assure requested scrapbook
  3405. #                        element exists.
  3406. #                        Added error checking to make sure Cut or Copy menu
  3407. #                        item selection was successful - if not, routine
  3408. #                        closes ScrapBook and aborts (returning 0).
  3409. #    NJV/KTA    7/13/90        took out wait
  3410. #                        added while ! match [window t:'Scrapbook' o:1]!);
  3411. #    NJV/KTA    7/17/90        changed copyFlag to ccpFlag for paste and clear
  3412. #                        bug fix from previous re-work
  3413. #    NJV        10/9/90        If 7.0, calls LaunchTwitch instead of closing Scrapbook
  3414. #    NJV        11/27/90    Updated documentation
  3415. #    KTA        1/9/91        Added scrap := 1 to 4
  3416. #    KTA        1/24/91        Took out a unneeded comment about checking in the Apple Menu
  3417. #    KTA        1/30/91        put in fix for 7.0ß4 where sound button is control [1]
  3418. #    KTA        2/18/91        Took out integration - May put this in the Integrate.lib
  3419. #    KTA        2/25/91        LaunchTwitch PreviousApp if can launch Scrapbook
  3420. #    KTA        9/31/91        Took out patch for sound
  3421. #    KTA        4/16/92        6.0x Support
  3422. #    KTA        4/20/92        Changed title to ordinality for intl
  3423. #########################################################################
  3424. task Scrapbook(requestElement,ccpFlag := 1,pasteFlag := 1) 
  3425. begin
  3426.     Global isSys7,Integration;
  3427.     temp := Integration;    
  3428.     Integration := 0;            #To turn off global Integration - KTA
  3429.     println "==========================================================";
  3430.     LogStr("Performing Scrapbook DA test.");
  3431.     if (ccpFlag > 4)
  3432.         ccpFlag := 1;    # old default is copy
  3433.         
  3434.     If(LaunchTwitch('Scrapbook')) 
  3435.     begin
  3436.         scBook := match [window t:'Scrapbook' o:1]!;
  3437.  
  3438.         if(scBook.k[1].t = 'Play Sound') #put in fix for 7.0ß4 where sound button is control [1]
  3439.             SkrollBar := scBook.k[2];
  3440.         else
  3441.             SkrollBar := scBook.k[1];
  3442.         status := SkrollBar.s;
  3443.         if (status <> { 0, -1 })                 # if scrollbar is enabled...
  3444.         begin
  3445.             error := 0;                                # no errors yet
  3446.             elementCount := status[2] + 1;            # elementCount = number of scrapbook elements
  3447.             currentElement := status[1] + 1;        # currentElement = current position in Scrapbook
  3448.             newCount := elementCount + 1;
  3449.     
  3450.             if (requestElement>elementCount)    # if position is greater than total elements in Scrapbook.. 
  3451.             begin
  3452.                 if (ccpFlag = 1)
  3453.                     LogStr("!@#$% Scrapbook entry {requestElement} does not exist! - Copying entry {currentElement} of {elementCount}");
  3454.                 else if (ccpFlag = 3)
  3455.                     LogStr("!@#$% Scrapbook entry {requestElement} does not exist! - Pasting to entry {currentElement} of {newCount}");
  3456.                 else 
  3457.                 begin
  3458.                     LogStr("!@#$% Can∂'t Cut/Clear - Scrapbook entry {requestElement} does not exist! Closing Scrapbook!");
  3459.                     error := 1;    # don't clear or cut if requested item not there
  3460.                 end;
  3461.             end;
  3462.             else # we've got a valid Scrapbook entry
  3463.             begin
  3464.                 scroll SkrollBar a:{requestElement,elementCount};
  3465.                 match [scrollbar s:?status]!;
  3466.                 currentElement := status[1] + 1;        # currentElement = current position in Scrapbook
  3467.                 LogStr("Scrolled to item {currentElement} of {elementCount} of the ScrapBook");
  3468.                 wait(1);
  3469.             end;
  3470.             
  3471.             if (not error) 
  3472.             begin
  3473.                 if (ccpFlag = 1) begin    # Copy Item
  3474.                     if (not SelectMenuItem(4, 3))    # error - couldn't copy
  3475.                         error := 1;        # prepare to abort
  3476.                 end;
  3477.                 else if (ccpFlag = 2)  begin
  3478.                     if (not SelectMenuItem(3, 3))    # error - couldn't cut    
  3479.                         error := 1;        # prepare to abort
  3480.                 end;
  3481.                 else if (ccpFlag = 3)  begin
  3482.                     if (not SelectMenuItem(5, 3))    # error - couldn't paste    
  3483.                         error := 1;        # prepare to abort
  3484.                     else
  3485.                         LogStr("Pasted to entry {currentElement} of {newCount}");                        
  3486.                 end;
  3487.                 else if (ccpFlag = 4)  begin
  3488.                     if (not SelectMenuItem(6, 3))    # error - couldn't clear    
  3489.                         error := 1;        # prepare to abort
  3490.                 end;
  3491.             end;
  3492.             wait(2);
  3493.             Integration := temp;            #To reset the integration global - KTA
  3494.             if (isSys7)
  3495.                 LaunchTwitch(Global PrevAppTitle);
  3496.             else                    # 6.0 Support since process list is different
  3497.             begin
  3498.                 temp2 := global Appverify;
  3499.                 Appverify := 0;
  3500.                 CloseWindow(,,'ScrapBook');        # close ScrapBook
  3501.                 Appverify := temp2;
  3502.                 MatchApp(0);
  3503.             end;
  3504.             if (error)
  3505.                 return(0);
  3506.             if (pasteFlag)    begin    # if we're supposed to paste back into document, do it
  3507.                 wait(3);
  3508.                 if (SelectMenuItem(5, 3)) begin
  3509.                     println "==========================================================";
  3510.                     return(1);
  3511.                 end;
  3512.             end;
  3513.             return(currentElement);    # everything went OK
  3514.         end;
  3515.         else 
  3516.         begin
  3517.             LogStr('!@#$% The horizontal scroll bar was not enabled to scroll');
  3518.             closeWindow();
  3519.             return(0);
  3520.         end;
  3521.     end;
  3522.     else 
  3523.     begin
  3524.         LogStr("Couldn't open the ScrapBook for some reason");
  3525.         if (Global isSys7)
  3526.             LaunchTwitch(Global PrevAppTitle);
  3527.         return(0);
  3528.     end;
  3529. end; # Scrapbook()
  3530.  
  3531. #########################################################################
  3532. #                         Quit(OverWrite, DocName)
  3533. #=======================================================================
  3534. # Author:          KTA
  3535. # Description:    Will turn off the Application Verification scheme, Select
  3536. #                the Quit menu item, check whether or not to save changes,
  3537. #                then reset the App verification scheme to its previous state.
  3538. # Parameters:    OverWrite    1    - Save changes.
  3539. #                            0    - Don't save changes.
  3540. #                DocName        -    The string that will be used to save the document
  3541. #                HowQuit        1    - Select "Quit" from File Menu
  3542. #                            2    - Type Cmd-Q to quit
  3543. # Returns:        Nada
  3544. #=======================================================================
  3545. # History:
  3546. #    KA        8/23/90        Created
  3547. #    NJV        11/25/90    Added KeepScrapOpen parameter to bypass KAs assumption
  3548. #                        that ScrapBook is open (fix in scrapbook for 6.0 world).
  3549. #    KTA        12/18/90    Took out KeepScrapOpen parameter-auto close Scrap
  3550. #    KTA        1/8/91        Moved endTime
  3551. #    KTA        1/9/91        Added HowQuit
  3552. #    KTA        2/18/91        Added While(CheckYesNo)
  3553. #########################################################################
  3554. task Quit(OverWrite :=1,DocName:="",HowQuit :=1) begin
  3555.     temp := global Appverify;
  3556.     AppVerify := 0;
  3557.     global startTime;
  3558.     if (HowQuit = 1)
  3559.         SelectMenuItem('Quit','File');     #Quit MenuItem
  3560.     else if (HowQuit = 2)
  3561.         keyEq('q');                        #Key Equiv 'q'
  3562.     while(checkYesNo(overwrite))
  3563.     begin
  3564.         If(overWrite)
  3565.             if (match[button t:"Save"]!) or (match[button t:"OK"]!)        # If SF dialog comes up     #
  3566.                 NameOk(DocName,true);
  3567.         wait(3);
  3568.     end;
  3569.     endTime := Timer(3);
  3570.     if (isUndefined(startTime))
  3571.         elTime := "not calculated because no one bothered to start the timer!!!)";
  3572.     else
  3573.         elTime := ETime(startTime,endTime);
  3574.     println "Total Elapsed time was {elTime}";
  3575.  
  3576.     wait(1);
  3577.     if match[window o:1 t:"Scrapbook"]!
  3578.         closeWindow(,,"Scrapbook");
  3579.     wait(2);
  3580.     KeyEq('w',2);
  3581.     AppVerify := temp;
  3582.     MatchApp();
  3583.     println;
  3584. end; # Quit()
  3585.